G
Gordon Airporte
I'm trying to get my canvas to resize to fill its frame within a window,
but I can't figure out how to handle the callback data from the window's
<Configure> properly. It has very strange behavior - resizing randomly
or growing by itself, shrinking to 0. The following works passably but
jumps around at random if you move the window and goes nuts if you add
the button (watch any wrapping):
from Tkinter import *
class testApp2:
def __init__( self, master ):
self.ma = master
self.f = Frame( self.ma )
self.f.pack()
self.cv = Canvas(self.f, width=25, height=25, bg='red')
self.cv.pack()
#self.b1 = Button( self.f, text='hello', command=None )
#self.b1.pack(side='bottom')
self.ma.bind('<Configure>', self.resize )
def resize( self, event ):
#print '(%d, %d)' % (event.width, event.height)
self.cv.configure( width = event.width-4, height = event.height-4 )
root = Tk()
app = testApp2(root)
root.mainloop()
but I can't figure out how to handle the callback data from the window's
<Configure> properly. It has very strange behavior - resizing randomly
or growing by itself, shrinking to 0. The following works passably but
jumps around at random if you move the window and goes nuts if you add
the button (watch any wrapping):
from Tkinter import *
class testApp2:
def __init__( self, master ):
self.ma = master
self.f = Frame( self.ma )
self.f.pack()
self.cv = Canvas(self.f, width=25, height=25, bg='red')
self.cv.pack()
#self.b1 = Button( self.f, text='hello', command=None )
#self.b1.pack(side='bottom')
self.ma.bind('<Configure>', self.resize )
def resize( self, event ):
#print '(%d, %d)' % (event.width, event.height)
self.cv.configure( width = event.width-4, height = event.height-4 )
root = Tk()
app = testApp2(root)
root.mainloop()