Tkinter Button dimensions

E

Elaine Jackson

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.

Peace
 
E

Eric Brunel

Elaine said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top