Image buttons with Tkinter

Hans Nowak hnowak at cuci.nl
Mon Nov 8 17:36:10 EST 1999


On 8 Nov 99, at 10:17, Thomas Lane wrote:

> I'm trying to create a button that displays an image instead of text, but
> I don't seem to be having any luck. The button just comes up gray. Here is
> a code snippet of what I'm trying to do:
> 
>   # Put remove.gif on a button (actionbar is a frame for various
> controls)
>   deletebutton = Button(actionbar,image=PhotoImage(file="remove.gif"))
>   deletebutton.place(x=0)

This code worked for me (I threw in a label so the button will be 
clearly visible rather than taking up the whole frame):

#--------------------------
# button-with-gif.py

from Tkinter import *

root = Tk()

image1 = PhotoImage(file='burger.gif')

button = Button(root, image=image1)
button.pack()

Label(root, text="Bwahahaha").pack()

root.mainloop()

#------------------------

> What am I doing wrong here?

Dunno, it looked good to me, although I never use the 'place' thingy.

> Also, is there a place on the net where I can find lots of sample
> Python/Tkinter code? I've read Fredrik Lundh's intro, but I haven't been
> able to find any other code or reference material for Tkinter.

As far as I know, the Tk introduction is about the best you can get 
at the moment. <waiting for Tk books...>

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
You call me a masterless man. You are wrong. I am my own master.




More information about the Python-list mailing list