Tkinter - Resizing a canvas with a window

Jeff Epler jepler at unpythonic.net
Tue Jul 26 21:22:30 EDT 2005


You should just use 'pack' properly.  Namely, the fill= and expand=
parameters.  In this case, you want to pack(fill=BOTH, expand=YES).
For the button, you may want to use pack(anchor=E) or anchor=W to make
it stick to one side of the window.

The additional parameters for the button (both creation and packing)
give a geometry that is closer to the standard buttons in Windows 95
/ Windows 2000.  Use those or not, as you see fit.

Here's the new program:

from Tkinter import *

class testApp2:
     def __init__( self, master ):
         self.ma = master
         self.f = Frame( self.ma )
         self.f.pack(fill=BOTH, expand=YES)
         self.cv = Canvas(self.f, width=25, height=25, bg='red')
         self.cv.pack(fill=BOTH, expand=YES)
         self.b1 = Button( self.f, text='Hello', height=1, width=10,
                            padx=0, pady=1)
         self.b1.pack(side=BOTTOM, anchor=E, padx=4, pady=4)



root = Tk()
app = testApp2(root)
root.mainloop()

Jeff
PS thanks for including a full, runnable program in your post!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050726/ecb12601/attachment.sig>


More information about the Python-list mailing list