[英]tk: do I need to mention the widget master?
I want to rearrange frames in PanedWindows at runtime based upon user request. 我想根据用户请求在运行时在PanedWindows中重新排列帧。 Previously I specified the master for each frame (here pw1). 以前,我为每个帧(此处为pw1)指定了一个母版。 Ex: 例如:
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()
What is the advantage of specifying the master? 指定母版有什么好处?
The master
paremeter can be interpreted as parent
. master
参数可以解释parent
参数。 Passing this will add a new key in the parent.children
attribute. 传递此参数将在parent.children
属性中添加一个新密钥。
If you print pw1.children
when you do not pass master
AND do not execute pw1.add()
you will see that it returns an empty dictionary. 如果打印pw1.children
当你不通过master
,不执行pw1.add()
你会看到它返回一个空的字典。
print pw1.children
#{}
The pw1.add()
method also includes the added widget in the pw1.children
dictionary. pw1.add()
方法还在pw1.children
字典中包含添加的小部件。 I still did not understand why when you pass master
the widgets are not automatically shown. 我仍然不明白为什么当您通过master
窗口小部件不会自动显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.