Python 3.3 Tkinter LabelFrame 可调整大小 [英] Python 3.3 Tkinter LabelFrame resizable

查看:102
本文介绍了Python 3.3 Tkinter LabelFrame 可调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建可调整大小的 LabelFrame?
或者有什么办法?
是否可以将 ttk.PanedWindowLabelFrame 一起使用?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆