2

I would assume the the reason is similar to self which i get.Why is master there? Also, why is it sometimes master and sometimes master = none?

e.g

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.grid()
        self.createWidgets()

from Tkinter 8.5 reference: a GUI for Python by John W. Shipman. Also, the doc uses python2 while I will be using python3. Do I need master? More problems I tried adding custom arg after master and it said I can't add a non-default arg after a default, how should I fix? doesn't the default arg self have to be first?

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
4

1 回答 1

2

Your Application class is a subclass of tk.Frame. The master parameter is the parent widget and it is an optional parameter (by default it is none) that will be passed to the new instance of Application class when it is initialized.

Take a look here for more info.

于 2013-08-05T21:27:28.270 回答