Tkinter pack method confusion

后端 未结 3 1493
别跟我提以往
别跟我提以往 2020-12-12 01:43

I cant understand why the pack manager wont let you pack LEFT AND RIGHT below top packed widgets. My expected output of the following code would be

 A
 B
C D         


        
3条回答
  •  渐次进展
    2020-12-12 02:38

    A work-around is to pack the C + D frames in a temp LabelFrame, then you can just pack it underneath B.

    import tkinter as tk
    
    root = tk.Tk()
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.state('zoomed')
    root.geometry("%dx%d+0+0" % (w-15, h-75))
    A = tk.LabelFrame(root,text='A', bd=2)
    B = tk.LabelFrame(root,text='B', bd=2)
    
    temp = tk.LabelFrame(root)
    
    C = tk.LabelFrame(temp,text='C', bd=2)
    D = tk.LabelFrame(temp,text='D', bd=2)
    E = tk.LabelFrame(root,text='E', bd=2)
    
    A.pack(fill=tk.BOTH, expand=tk.TRUE)
    B.pack(fill=tk.BOTH, expand=tk.TRUE)
    C.pack(side=tk.LEFT,fill=tk.BOTH, expand=tk.TRUE)
    D.pack(side=tk.RIGHT,fill=tk.BOTH, expand=tk.TRUE)
    temp.pack(expand=tk.TRUE, fill=tk.BOTH)
    E.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=tk.TRUE)
    
    root.mainloop()
    

提交回复
热议问题