Yuxiang Wang
Yuxiang Wang

Reputation: 8423

The first argument for python Tkinter

I am using Tkinter with python 2.7 and am curious about why the following code snippet would work:

import Tkinter as tk
import ttk

class Application(ttk.Frame):

    def __init__(self, master=None):
        ttk.Frame.__init__(self, master) # This is where my question is
        self.grid()
        return

if __name__ == '__main__':
    root = tk.Tk()
    app = Application(root)
    root.mainloop()

1) The ttk.Frame.__init__ takes one argument, which is the master. But now the first argument is an instance inherited from it, and the second is master. How did this work?

2) I noticed that the ttk.Frame class also have a function called mainloop. How is this different from root.mainloop()?

Thanks!

Upvotes: 1

Views: 210

Answers (1)

fred.yu
fred.yu

Reputation: 865

1) ttk.Frame.__init__() in method Application.__init__() is used to initialize base class ttk.Frame, the explaination doc is here.

2) mainloop() in ttk.Frame and root.mainloop() is equal, please look at this.

Upvotes: 3

Related Questions