Tkinter Question

Gary Herron gherron at aw.sgi.com
Wed Jun 9 12:12:54 EDT 1999


Robert Meegan wrote:
> 
> Greetings ---
> 
> I have an alarm display that consists of a  Frame that contains multiple
> frames within it, stacked one above the other. When a user clicks on one
> of the subframes to acknowledge it, I want the subframe to disappear and
> the parent frame to resize itself to remove the gap.
> 
> Getting the subframe to remove itself is no problem. I bound the
> <Button-1> event to a method and had the frame destroy itself. Life is
> good.
> 
> On the other hand, I can't figure out how to make the parent frame resize
> itself.
> 
> Suggestions will be greatly appreciated.
> 
> --- Robert
> 
> --------------------------------
> Robert Meegan
> MCIWorldCom - Cedar Rapids, Iowa
> 319.375.2416

You probably used `pack' to put each subframe into the main frame, so
you should use its inverse operation `forget' to take it out.  Then the
parent frame resizes automatically.

Here is a very small example:  poke any of the buttons and watch it
disappear and the frame resize around the remaining buttons.

-- 
Dr. Gary Herron <gherron at aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101
-------------- next part --------------
#!/usr/bin/env python

from Tkinter import *

root = Tk()

for i in range(10):
	f = Frame(root)
	b = Button(f, text='%s'%i,
			   command=lambda f=f: f.forget())
	b.pack()
	f.pack()

root.mainloop()


More information about the Python-list mailing list