Tkinter - Resizing a canvas with a window
Gordon Airporte
fake at comcast.net
Wed Jul 27 14:28:50 EDT 2005
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()
More information about the Python-list
mailing list