[tkinter] widget size adjustment

Christian Gollwitzer auriocus at gmx.de
Tue Jun 21 16:18:26 EDT 2016


Am 21.06.16 um 19:24 schrieb Pierre-Alain Dorange:
> A picture is often better than words, here is a scren capture of my apps
> before and after resing the main window :
> <https://dl.dropboxusercontent.com/u/722984/pmx-grid.pdf>
>
> It was a map viewer similar to online javascript mapviewer but in a
> local apps : with the main central part a canvas widget (with a PIL
> image put build and put in).
>
> I would resze the canvas according to the space available when the user
> resize the window.
> As you can see in the screen capture, when resize, the main map widget
> is not resized, only centered.

Perhaps your assumption is wrong. Maybe the canvas itself *is* resized, 
so the white space you see around the image is the background of the 
canvas. To test this easily, set a strong color for the background:

	blabla = tk.Canvas(..., bg='red')

You should see red space appear when you resize the window. If you see 
white space, then the options are not set properly and the canvas is not 
resized.

I assume that you want the following: Upon resizing the main window, the 
map image should be stretched to fill the space, right? Then you'll have 
to do that on your own. First, bind a Configure event to the canvas

	canvas.bind('<Configure>', callback)

The callback functino now gets called when the canvas needs to be 
redrawn. In that callback function, you get the new width and height 
from the event object. Resize the image accordingly (using a PIL function).

	Christian



More information about the Python-list mailing list