Tkinter Button dimensions

Eric Brunel eric_brunel at despammed.com
Fri Jul 2 10:23:31 CEST 2004


Elaine Jackson wrote:
> In the script I'm writing, there's a Tkinter Button that contains a square image
> at some times and is blank at other times. Is there a smart way to make its
> dimensions stay the same throughout all this? Any help will be greatly
> appreciated.

Two solutions come to mind:
- specifying a width and a height for the button; a bit awkward, since the unit 
taken for the dimensions depends on what is displayed in the button (pixels for 
an image; characters for text). And configuring the button size when nothing is 
displayed in it seems to take dimensions in characters, which is not suitable 
for what you want to do.
- create an empty image of the same size of the existing one and set this image 
for the button when it should be empty. Example:

from Tkinter import *
root = Tk()
img = PhotoImage(width=50, height=50)
Button(root, image=img).pack()
root.mainloop()

This may be the best solution for what you want to do.

HTH
-- 
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list