[Tutor] Please Critque Tkinter Class for Newbie

Michael P. Reilly arcege@speakeasy.net
Thu, 12 Jul 2001 08:20:18 -0400 (EDT)


Sheila King wrote
> :Just two comments.  A widget should not pack itself as your Palette does.
> :That should be the application's choice.  If there are some "adjustments"
> :you want, then override the method to modify the parameters.
> 
> Oops. That was just plain dumb. I probably had that statement in there
> from very early in my writing/testing phase and forgot to take it out.
> It is now gone, and the class works just as I want it to. As a matter of
> fact, I'm surprised, that since the class (as I originally posted it)
> packed itself, and then my __main__ function packed it again, that this
> didn't create some kind of error.

Tkinter will allow a widget to be repacked.  The issue is that you
cannot mix geometry managers.  So if you want to use the Place or Grid
managers, then this will be a problem (need to call pack_forget first).
Wouldn't be an error, but you get interesting results if you try:

>>> from Tkinter import *
>>> root = Tk()
>>> b = Button(root, text='bye', command=root.quit)
>>> e = Entry(root)
>>> b.pack()
>>> e.grid()

On my Linux system, I get a window that continually changes between
the two widgets which are in the same space - so fast that I can't even
click on the quit button, which wouldn't work since I'm not in mainloop.
(It's kind of neat to watch, but I just had a MRI this morning, so it
giving me a worse headache.  I'll have to address your other question
later today.)

> You know, I later was reading in PP2, and saw examples that did just
> like I had in my class...well, not exactly. They had a self.pack()
> statement in the class, and the if __name__=='__main__' block didn't not
> have the object being packed again. However, the module was reused later
> in the book, and they did repack the object in the main program file.
> Why would the author do it that way?

Mostly because he's just writting little demos and that most things use
pack instead of grid or place.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |