Tkinter canvas resize question

Russell E. Owen owen at astroNOJNK.washington.edu.invalid
Mon Jul 17 13:43:33 EDT 2000


I have a Tkinter canvas (along with a few other widgets) in a window. I 
want the canvas widget to resize whenever the window resizes (the other 
widgets are fields with fixed height). Not a problem, so far.

But...I'd also like to resize the contents of the canvas whenever the 
user resizes the window.

I have been catching the <Configure> event, but this is not very 
satisfactory because I see it before the canvas does. I've been manually 
configuring canvas to a new size, but this is potentially unstable -- if 
I don't set exactly the size the frame wants, the frame will generate a 
new <Configure> event, leading to many cycles of size changing.

What I'd really like is for the canvas to resize itself (i.e. perform 
all the standard negotiations with its master) and then tell me it has 
been resized, so I can redo its contents. Is there some easy way to do 
this?

Saving this, is there some easy way to catch <Configure>, pass it to 
canvas (as if I'd never intercepted it) and then ask canvas what size it 
has become and redo its contents accordingly?

I do have John Grayson's book "Python and Tkinter Programming"; the info 
is likely in there, but I haven't found it. I suspect I should also have 
a complete Tk reference, and would welcome suggestions.

-- Russell

P.S. another useful thing would be to have a window that contained a 
canvas of a particular aspect ratio (say 1:1, square). When the user 
resized the window, the window would retain the newly requested height, 
but the width would change as needed to give the canvas its desired 
aspect ratio. Is this sort of thing possible, and what is involved? 
Writing a new layout manager?



More information about the Python-list mailing list