繁体   English   中英

tk:我需要提一下窗口小部件大师吗?

[英]tk: do I need to mention the widget master?

我想根据用户请求在运行时在PanedWindows中重新排列帧。 以前,我为每个帧(此处为pw1)指定了一个母版。 例如:

import Tkinter as tk

root = tk.Tk()

pw1 = tk.PanedWindow(orient=tk.HORIZONTAL, sashpad=2,
    sashwidth=4, sashrelief=tk.RAISED)
pw1.pack(fill=tk.BOTH, expand=1)

frame1 = tk.Frame(pw1, bg='red',width=100, height=100) 
frame2 = tk.Frame(pw1, bg ='yellow',width=100,height=100)

# This seems to do the same thing:
# frame1 = tk.Frame(bg='red',width=100, height=100) # vs. tk.Frame()
# frame2 = tk.Frame(bg ='yellow',width=100,height=100) 

pw1.add(frame1, sticky=tk.NSEW)
pw1.add(frame2, sticky=tk.NSEW)

root.mainloop()

指定母版有什么好处?

master参数可以解释parent参数。 传递此参数将在parent.children属性中添加一个新密钥。

如果打印pw1.children当你不通过master 不执行pw1.add()你会看到它返回一个空的字典。

print pw1.children
#{}

pw1.add()方法还在pw1.children字典中包含添加的小部件。 我仍然不明白为什么当您通过master窗口小部件不会自动显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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