#images_sample.py from Tkinter import * def addGraphicalButton(parent): # Create the PhotoImage widget try: im = PhotoImage(file='cake.gif') button2 = Button(root, text="Potato", image=im) button2.image = im button2.pack() except TclError, moreDetails: print 'There was an error. No file was found... creating a standard button instead. The error was:\n\n', moreDetails button2 = Button(root, text="Potato") button2.pack() root = Tk() # Create the root (base) window where all widgets go addGraphicalButton(root) root.title("This is image sample") root.mainloop() # Start the event loop