[英]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.