我认为原因与我得到的self相似。为什么师父在那里?还有,为什么有时是master,有时master=none?
例如
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
来自Tkinter 8.5参考:John W.Shipman的Python GUI。此外,doc使用python2,而我将使用python3。我需要大师吗?更多问题我试着在master之后添加自定义arg,它说我不能在默认之后添加非默认arg,我应该如何修复?默认的arg self不是必须是第一个吗?
def __init__(self, master=None,inputDict):
tk.Frame.__init__(self, master)
self.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.createWidgets()
def createWidgets(self,inputDict):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
tempDict = {}
for k,v in inputDict.items():
if 1<=v[0]<=3:
tempDict[k] = static_keys(*v[1:])
elif v[0] ==4:
tempDict[k] = dynamic_keys(*v[1:])
elif v[0]==5:
tempDict[k] = key_labels(*v[1:])
return tempDict
您的Application
类是tk.Frame
的子类。master
参数是父窗口小部件,它是一个可选参数(默认情况下为none
),初始化时将传递给Application
类的新实例。
查看此处了解更多信息。