To answer your questions in order
The
master
argument is the "parent widget" for each widget, and defaults toNone
forTkinter.Frame
. Note you passself
(i.e. theFrame
) asmaster
to eachButton
;That's not really a question, but if you change the definition to
def __init__(self)
then callapp = Application(root)
you will get aTypeError
, as theroot
argument has nowhere to go; andThe point of setting
app = Application(root)
is simply that you can then access it later. Your example is simple, with no instance methods to call outside__init__
, but that may not always be the case.
To clarify on 1., note that
class Application(Tkinter.Frame):
means that all Application
class instances inherit methods and attributes from Tkinter.Frame
. This is not the same as the function arguments in e.g.
def __init__(self, master):
which means that Application.__init__
takes two arguments (the first, called self
by convention in all instance methods, is the class instance itself and is usually passed implicitly). When you call
app = Application(root)
this relates to the __init__
definition, and (roughly) means
Application.__init__(app, root)
If __init__
doesn't have two arguments (self
and master
), you will therefore get a TypeError
, as there are two arguments (the implicit instance self
and explicit parent widget master
) and Python only knows what to do with one of them.