Tkinter: Do you really need a "root"?

Bob Smith bobsmith327 at hotmail.com
Sat Jun 7 18:50:18 EDT 2003


Hi.  I'm just starting to learn to use the Tkinter module for creating
GUIs.  I'm using a tutorial that gives a basic starting program of:

from Tkinter import *
root = Tk()
app = Frame(root)
root.mainloop()

But do I really need root?  It seems like the program could simply be:

from Tkinter import *
app = Frame()
app.mainloop()

This second program works just as well as the first and seems more
intuitive to me.  I'm creating an application that is a Frame and I
start the application by invoking the application's mainloop() method.

The first example seems more obtuse.  root seems unnecessary and
invoking root's mainloop() instead of app's seems odd to me too (if I
want to start app, I should invoke a method of app).

So, what's wrong with the second version?  Will I run into problems
later when I add more widgets and get into more complex GUIs?

Thanks,
Bob




More information about the Python-list mailing list