[Tutor] GUIs and Classes
Alan Colburn
aicolburn@yahoo.com
Fri, 13 Sep 2002 14:05:53 -0700
As a beginner to the world of GUI toolkits, I've noticed that most of the
tutorials I've seen (regardless of the toolkit being taught) follow a
similar pattern. There's an aspect to the examples that I don't really
understand. Perhaps someone can clarify for me. I'll use Tkinter for this
message.
A typical program might look like this (I'm borrowing this from the
'Thinking in Tkinter' site):
from Tkinter import *
class MyApp:
def __init__(self, myParent):
self.myContainer1 = Frame(myParent)
self.myContainer1.pack()
##various other widgets are added here
root = Tk()
myapp = MyApp(root)
root.mainloop()
The part I don't understand relates to the reason the GUI is set up within
its own class. It doesn't have to be. In addition, I'm not quite sure of the
difference between the root and the frame. If I simply bound all the widgets
to the root object the GUI would look the same.
Thoughts? Thanks, as always -- Al
p.s. My thanks to those of you who recommended 'Beginning Java Objects' to
me as a way to better understand OOP. I'm enjoying the book very much.