[tkinter] widget size adjustment
Christian Gollwitzer
auriocus at gmx.de
Wed Jun 22 16:18:12 EDT 2016
Am 22.06.16 um 19:42 schrieb Pierre-Alain Dorange:
> Christian Gollwitzer <auriocus at gmx.de> wrote:
>
>> 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've allready a background by not displayed, so the canvas is not
> automatilly resized.
If you do not see the background, then indeed the canvas is not resized,
which means the gridding options are wrong. Looking at your code, I see
this:
self.map.grid(row=1,column=1,rowspan=4,columnspan=2,padx=2,pady=2)
Here, you do not specify any sticky options, which means it should
default to centering. Try adding NSEW sticky options.
>> 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)
>
> I do this, the callback is called when window was resized, but
> unfortunnally i was not able to get the "available space (in pixels)".
>
> event.width and event.height just return the actual canvas size... not
> useful
This is a consequence of the missing grid options. On resize, the canvas
is only moved which also triggers the Configure event. If you set the
grid options correctly, you should get the new size. You will then need
to compute an updated image.
Christian
More information about the Python-list
mailing list