如何在水平形状中将 LabelFrame 位置从右侧更改为底部

问题描述 投票:0回答:2
root = Tk()
centerRoot()
root.state('zoomed') 
root.title('sample data')

# Menu Configuration
menubar = Menu(root, background='#E4FDE1', foreground='blue', activebackground='white', activeforeground='black',font="myFont")
tab1 = Menu(root,tearoff=0, background='#E4FDE1', foreground='blue', activebackground='white', activeforeground='black',font="myFont")  
menubar.add_cascade(label="File", menu=tab1)  
tab2 = Menu(menubar, tearoff=0,background='#E4FDE1', foreground='blue', activebackground='white', activeforeground='black',font="myFont") 
menubar.add_cascade(label="Tools" , menu=tab2)   



frame1 = LabelFrame(root, text="pKa")
frame1.pack(side=LEFT,fill="both", expand=False,padx=5,pady=5)

frame2 = LabelFrame(root, text="%")
frame2.pack(side=LEFT, expand=True, fill=BOTH,padx=5,pady=5)

frame3 = LabelFrame(root, text="RPM")
frame3.pack(side='left', expand=False, fill=BOTH,padx=5,pady=5)

ttk.Separator(
    frame1,
    orient=VERTICAL,
).pack(fill='none', expand=False)

ttk.Separator(
    frame2,
    orient=VERTICAL,
).pack(fill='none', expand=True)

ttk.Separator(
    frame3,
    orient=HORIZONTAL
).pack(fill='none', expand=True)
root.config(menu=menubar)
root.mainloop()

如何使用 pack() 方法将屏幕右侧的 Frame3 移动到水平形状的底部? 正好在 Fram2 下。 我应该怎么办 ?请帮我 谢谢

python user-interface tkinter ttk
2个回答
0
投票

如果你想要它在底部,告诉

pack
你想要它在底部。此外,因为您调用
pack
的顺序很重要,所以在打包其他框架之前打包它。

我发现,当您将对

pack
的所有调用放在一起并按其父级分组时,修复布局问题通常要容易得多,如下例所示:

frame3.pack(side=BOTTOM, expand=False, fill=BOTH,padx=5,pady=5)
frame1.pack(side=LEFT,fill="both", expand=False,padx=5,pady=5)
frame2.pack(side=LEFT, expand=True, fill=BOTH,padx=5,pady=5)

有关加壳器工作原理的规范描述,请参阅官方 tcl/tk 手册页中的加壳器算法


0
投票

如何在 HORIZONTAL 中将屏幕右侧的 Frame3 移动到底部 用 pack() 方法塑造?正好在 Fram2

注释掉

frame1.pack(...)
frame2.pack(...)
frame2.pack(...)
.

安排地点:

frame1.pack(side=LEFT,fill="both", expand=False,padx=5,pady=5)
frame3.pack(side=BOTTOM, expand=False, fill=BOTH,padx=5,pady=5) #<= under frame2
frame2.pack(side=LEFT, expand=True, fill=BOTH,padx=5,pady=5)

屏幕截图:正好在 Fram2 下.

看着 Bryan Oakley 的回答。

截图:不完全是在Fram2下

© www.soinside.com 2019 - 2024. All rights reserved.