Python 3.3 Tkinter LabelFrame 可调整大小 [英] Python 3.3 Tkinter LabelFrame resizable
问题描述
是否可以创建可调整大小的 LabelFrame
?
或者有什么办法?
是否可以将 ttk.PanedWindow
与 LabelFrame
一起使用?
Is it possible to create a resizable LabelFrame
?
Or any way?
And is it possible to use ttk.PanedWindow
with LabelFrame
for this?
这是我的代码:
fram1 = ttk.LabelFrame(root, text = "text1", height = 100, width = 200)
fram1.config(relief=FLAT)
fram1.pack(side = "right", fill="both", expand = True)
fram2 = ttk.LabelFrame(root, text = "text2", height = 100, width = 200)
fram2.config(relief=FLAT)
fram2.pack(side = "left", fill="both", expand = True)
而且我不能resize
这些labelframes
推荐答案
panedwindow 可以在一个窗格中容纳任何单个小部件,因此 labelframe 没有问题,并允许您添加更多小部件和 labelframe 的子项.一个例子:
The panedwindow can hold any single widget in a pane so a labelframe is no problem and allows you to add further widgets and children of the labelframe. An example:
import sys
from tkinter import *
from tkinter.ttk import *
def main():
app = Tk()
pw = PanedWindow(app, orient='vertical')
paneA = LabelFrame(pw, text="Pane A", height=240, width=320)
paneB = LabelFrame(pw, text="Pane B", height=240, width=320)
pw.add(paneA, weight=50)
pw.add(paneB, weight=50)
pw.pack(fill='both', expand=True)
app.mainloop()
if __name__=='__main__':
sys.exit(main())
权重允许您在更改容器大小时为每个窗格设置按比例缩放.如果两个窗格的权重相同,则它们的增长量相同.
The weight allows you to set a proportionate scaling for each pane as you change the size of the container. If both panes have the same weight then they grow by the same amount.
这篇关于Python 3.3 Tkinter LabelFrame 可调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!