Reading screen width of a Tkinter widget.

peter peter.mosley at talk21.com
Thu Oct 13 04:52:50 EDT 2011


I recently had a problem while trying to set up a Tkinter Canvas
widget as a progress bar.  Everything seemed to be working, except
that at 100% completion the progress bar spanned only about 75% of the
canvas width.  Eventually I tracked the problem down to the canvas bar
'width' property as read using w=cnvProgess['width'].  It turned out
the value returned was the original width of the canvas bar, and not
the screen width after the canvas had been gridded using 'sticky=W+E'.

Once I realised this it was not a show stopper, as I replaced the grid
sticky option with a specific width instruction.  But this is a bit
less flexible than my original method.  Is there any Tkinter command
which will return the actual dimensions of a widget which has had the
grid sticky option applied?

Peter




More information about the Python-list mailing list