Misc Tkinter questions

David Allen s2mdalle at titan.vcu.edu
Sat Jan 6 02:07:55 EST 2001


I've been looking through Frederick Lundh's introduction
to Tkinter, and the reference pages, but I'm left
with a lot of questions...mostly things that I'm used
to doing with other toolkits that I can't find out
how to do in python.  Any gaps that could be filled
in by anybody here would be greatly appreciated.

1.) How do you hide widgets?  (Is this wid.withdraw())
2.) How do you show widgets?  (undo 1.)
3.) How do you fix the size of a window?  I'm using
a window that's a subclass of Tk, and I would like
to know how to make it so that if the widgets within
the window shrink, the window stays the same size.
(i.e. put a solid minimum size on the window, which
can grow)
4.) Is it kosher to wid.destroy() something that's
packed into something else and then pack something
else in?  I.e.:

class Thingy(Frame):
   def __init__(self, *args):
      Frame.__init__(self)
      self.myframe = Frame(self)
      self.myframe.pack()
      self.button = Button(self.myframe,
                           text="foo", 
                           command=self.doIt)
      self.button.pack()
   def doIt(self, *args):
      self.button.destroy()
      self.button = Button(self.myframe, 
                           text="Bar",
                           command=self.doIt)
      self.button.pack()
      return None

I ask this because I"ve been getting a lot of very
strange exceptions out of Tkinter and Pmw recently,
and I'm wondering if this type of thing is related.

5.) Why can't you mix grid() and pack()?   (I ask
because I like grid layouts in most situations, but
I can't use fill=1, expand='x' when using grid)

6.) Is it better to create all of your widgets,
then pack them in going from the inside out, or
is it better to pack them as you create them?  Or
does it make a difference?  I.e. which is better:

THIS:
p = Panel(somepanel)
another = Panel(p)
yetanother = Panel(another)

yetanother.pack()
another.pack()
p.pack()

OR THIS:
p = Panel(somepanel)
p.pack()
another = Panel(p)
another.pack()
yetanother = Panel(another)
yetanother.pack()

Any help would be appreciated.  If there's some
documentation that I'm missing that makes any of
these questions silly, please point it out to me! :)

-- 
David Allen
http://opop.nols.com/
----------------------------------------
A free society is one where it is safe to be unpopular.
                -- Adlai Stevenson



More information about the Python-list mailing list