[tkinter] widget size adjustment

Christian Gollwitzer auriocus at gmx.de
Wed Jun 22 17:05:39 EDT 2016

Am 22.06.16 um 22:53 schrieb Pierre-Alain Dorange:
> Christian Gollwitzer <auriocus at gmx.de> wrote:
>> 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.
> That's magic !
> It works just fine...


> If i do understand NSEW sticky option make the widget autoadjust to the
> available space. The default option is just CENTERED... I do not explore
> this, i just thought NSEW was also CENTERED.

IMHO the sticky options in grid are actually very intuitive, once you 
understand them. The widget gets "pinned" on each side that is mentioned 
in the sticky set. If it is not pinned in one direction, then it is 
centered. So, for instance sticky=N means pin it on top (North), but 
neither south, east nor west. This means, the widget is aligned to the 
top of the cell and centered in left-right direction, but does not 
resize. Whereas, sticky=NS means pin it north and south, which is 
stretching in vertical direction to fill the height, center in 
left-right. sticky=NSEW pins it at all four sides which consequently 
stretches it in both directions.

BTW, the Tkinter wrapper is a bit clumsy for this option. In the 
original Tk, the sticky option is just a string. You can still pass that 
and do


instead of the clumsy



More information about the Python-list mailing list