[Tkinter-discuss] [Fwd: Re: pack and unpack a frame]

craf prog at vtr.net
Fri Jan 7 19:11:34 CET 2011


--------- Mensaje reenviado --------
> De: Michael Lange <klappnase at web.de>
> Para: tkinter-discuss at python.org
> Asunto: Re: [Tkinter-discuss] pack and unpack a frame
> Fecha: Fri, 7 Jan 2011 17:52:46 +0100
> 
> Hi,
> 
> Thus spoketh <prog at vtr.net> 
> unto us on Fri, 07 Jan 2011 13:44:14 -0300:
> 
> > Hi.
> > 
> > I'm testing the ability to pack and unpack a Frame control.
> > 
> > The code I use is:
> > -----------------------------------------------------------
> > 
> > import Tkinter
> > import ttk
> > 
> > class App:
> > 	def __init__(self, master):
> > 		self.root = master
> > 		self.frame = ttk.Frame(self.root, style='TFrame')
> > 		self.frame.pack(fill='both', expand='yes')
> > 		
> > 		self.b1 =  ttk.Button(self.root, text='unpack')
> > 		self.b1.pack()
> > 		
> > 		self.b2 = ttk.Button(self.root, text='pack')
> > 		self.b2.pack()
> > 		
> > 		
> > 		self.b1.bind('<Button-1>', lambda e, widget=self:unpack
> > (widget)) self.b2.bind('<Button-1>', lambda e, widget=self:pack(widget))
> > 		
> > def pack(widget):
> > 	widget.frame.pack()
> > 	print (widget.frame.pack_info())
> > 	
> > def unpack(widget):
> > 	widget.frame.pack_forget()
> > 	
> > 	
> > 
> > master = Tkinter.Tk()
> > master.geometry('640x480')
> > s = ttk.Style()
> > s.configure('TFrame', background='blue')
> > app = App(master)
> > master.mainloop()
> > -----------------------------------------------------------
> > 
> > Unpacking the Frame work, but in trying to repackage it does not work.
> 
> Actually it does work, however you do not see the frame, because there
> aren't any widgets inside it and you did not use the fill='both',
> expand='yes' flags when you re-packed it, so it will end up with 1x1
> pixels size. Here I can still see the blue pixel if I look closely right
> under the "pack" button :)
> 
> Regards
> 
> Michael
> 
> 
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.
> 
> Knowledge, sir, should be free to all!
> 		-- Harry Mudd, "I, Mudd", stardate 4513.3
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

Hi Michael.

Sometimes I'm blinder than a mole ;=)

Thanks you for the tips.

Regards.

Cristian Abarzua



More information about the Tkinter-discuss mailing list