1

Consider i create a Class Name "Application" which accepts "frame" widget

class Application(Frame):

In Constructor/Initialisation i do

def __init__(self, master=None):

When creating Instance

root = Tk()
app = Application(master=root)

i dont Understand when creating instance i am assigning instance of class Tk() to Master . then why in initialisation we are making it "None". can Some one look into this and Explain.

Thanks in Advance

4

1 回答 1

5

当您编写时,def __init__(self, master=None):您将 None 设置为 的默认master。当您调用时,Application(master=root)您传递的值会覆盖默认值。

A simple example:

def foo(a=1):
    print "a is", a

>>> foo()
a is 1
>>> foo(2)
a is 2
>>> foo(a=2)
a is 2
>>> 
于 2013-11-09T08:18:39.363 回答