Ewok
Ewok

Reputation: 21

Missing Frame/Not Appearing (Tkinter, Python)

I'm trying to create a GUI and was using Tkinter to create that GUI, I had one root with three different frames, one on the top, on the bottom left and one on the bottom right. The top hasn't been appearing and i was wondering if i did something wrong and how i could fix it. (I'm also very new to Tkinter and Python)

import tkinter as tk
from typing import Text
MainRoot= tk.Tk()
MainRoot.wm_geometry("800x500")
MainRoot.wm_title("Encode")



Encode_Frame = tk.Frame(MainRoot, bg="Gray", height=400, width=400)
Encode_Frame.pack(anchor="s",side=tk.LEFT)

Decode_Frame = tk.Frame(MainRoot, bg="Blue", height= 400, width=400)
Decode_Frame.pack(anchor="s",side=tk.RIGHT)

Text_Frame= tk.Frame(MainRoot,bg="Red",height=100,width=800)
Text_Frame.pack(side=tk.TOP, anchor= "n")



MainRoot.mainloop()

Upvotes: 1

Views: 908

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385880

The root cause is that you're packing the left and right sides first. The way the packer works, when you pack a widget it takes up an entire side. So, once you pack something on the left, nothing can appear above or below it. Likewise when you pack something on the right.

When you pack the left and right first, the only space left is in the middle between the two sides. So, your third frame is going to the top _of the space between the two sides. Since the two sides are already filling the entire width of the window, there's no room left for the top frame.

The simple solution is to pack the top frame first.

Text_Frame.pack(side=tk.TOP, anchor= "n")
Encode_Frame.pack(anchor="s",side=tk.LEFT)
Decode_Frame.pack(anchor="s",side=tk.RIGHT)

For a comprehensive explanation of pack with images, see this answer to the question Tkinter pack method confusion

Upvotes: 1

Related Questions