简体   繁体   中英

Tkinter: Why do child-frames not appear in one frame, but do in another?

I am learning tkinter.

I am trying to create the skeleton for an app right now, and I am working on learning tk.Frame( ). For background, I have a tk.Tk( ) root with 3 child tk.Frame( )s, and each of those will have a number of tk.Frame( ) children.

Now, things went as expected for creating the root and the 3 child frames in the master=root. Furthermore, the top child frame of root can have frames in it just fine. However, the frames that I put into the middle child frame of root do not display. Does anyone know why this may occur? Another issue is that a label that I have in one frame disappears once I put a child frame into a separate master frame.

My code below should help explain.

from commands import *

# create root
root = tk.Tk()
appTitle = "Fotoshoop"
root.title(appTitle)

factor = 1.618
rootWidth = 800
rootHeight = int(rootWidth / factor)
geo = "{}x{}".format(str(rootWidth), str(rootHeight))
root.geometry(geo)
# root.grid()

# LAYER 1
l1padx = 10
l1pady = l1padx
l1w = 200
l1h = int(l1w / factor)
l1color = "gray"

Header = tk.Frame(root, bg=l1color, width=l1w, height=l1h)
Header.grid(row=0, column=0,
            ipadx=l1padx, ipady=l1pady, padx=l1padx, pady=l1pady)

Transformations = tk.Frame(root, bg=l1color, width=l1w, height=l1h)
Transformations.grid(row=1, column=0,
                     ipadx=l1padx, ipady=l1pady, padx=l1padx, pady=l1pady)

Content = tk.Frame(root, bg=l1color, width=l1w, height=l1h)
Content.grid(row=2, column=0,
             ipadx=l1padx, ipady=l1pady, padx=l1padx, pady=l1pady)


# LAYER 2
l2padx = 5
l2pady = l2padx
l2color = "blue"

msg_header = "Welcome!"
Label_Header = tk.Label(Header, bg=l2color, text=msg_header)
Label_Header.grid(row=0, column=0, ipadx=l2padx,
                  ipady=l2pady, padx=l2padx, pady=l2pady)

Label_Header = tk.Label(Header, bg=l2color, text="PLACEHOLDER FOR LINKS")
Label_Header.grid(row=0, column=1, ipadx=l2padx,
                  ipady=l2pady, padx=l2padx, pady=l2pady)

#PROBLEM the following code does not display
#        in addition, once added, Label_Header does not display
Transformations_left = tk.Frame(
    Transformations, bg=l2color)
Label_Header.grid(row=0, column=0, ipadx=l2padx,
                  ipady=l2pady, padx=l2padx, pady=l2pady
                  )

root.mainloop()

Thank you!

You haven't called pack , place , or grid on Transformations_left .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM