September 27th, 2004, 12:51 AM
All I want to do is put an image on a button or label in Tkinter, I know it can be done but I'me totally confused with the dozens of different instructions,please how do I do it in 1 or 2 lines?
September 27th, 2004, 05:31 AM
To make a button with an image is a two stage process:
1. Create an image object in which to "hold" your image:
Tkinter supports gif transparency which is very useful for most buttons.
imageobj = Tkinter.PhotoImage(file="Path of my gif image file")
2. Then configure your button to use the image opbject
When you use an image the height and width parameters of a button still apply but they now correspond to pixels.
mybutton = Tkinter.Button(myframe, text = "Any old text", image = imageobj, ... plus any other confiuration stuf)
BTW Did you know you can add Tooltips to your Tkinter applications? There is a module in the Idle directory that demonstrates it - with slight modification it will integrate easily into your Tkinter application. I use it when there are graphical buttons - if the user hesitates over a button up pops the text that would have been on the button if the graphic was not there.