Re: Tkinter - Resizing a canvas with a window
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Tkinter - Resizing a canvas with a window

From: Gordon Airporte <fake@comcast.net>
Date: Wed Jul 27 2005 - 20:28:50 CEST

Thanks you very much. I found something interesting though, the canvas's
width and height properties are not updated when it is resized by its
packing. Looks like an oversight to me, but I've just demonstrated that
I don't have a complete grasp of Tk, so... I can use a Configure
callback to keep track of the values, however.

from Tkinter import *

class testApp3:
     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=125, height=125, bg='red')
         self.cv.pack(fill=BOTH, expand=YES)
         self.b1 = Button( self.f, text='Hello', height=1, width=10,
padx=0, pady=1, \
                           command = self.howbig )
         self.b1.pack(side=BOTTOM, anchor=S, padx=4, pady=4)
         self.cv.bind('<Configure>', self.resize )

     def howbig( self ):
         print self.cv['width'], self.cv['height']
         print self.cvw, self.cvh

     def resize( self, event ):
         print '(%d, %d)' % (event.width, event.height)
         self.cvw, self.cvh = event.width-4, event.height-4

root = Tk()
app = testApp3(root)
root.mainloop()
Received on Thu Sep 29 17:11:47 2005