I took the liberty to modify vegaseat's previous example code to show you how buttons would work:
from Tkinter import *
root = Tk()
root.title("Press Button!")
def show_image2():
canvas1.create_image(x, y, image=photo2)
def show_image3():
canvas1.create_image(x, y, image=photo3)
# pick three GIF image files you have in your working directory
# image1 is larger than image2 and image3
# create all three image objects now
image1 = "Red200x200.GIF"
photo1 = PhotoImage(file=image1)
image2 = "Green100x100.GIF"
photo2 = PhotoImage(file=image2)
image3 = "Blue100x100.GIF"
photo3 = PhotoImage(file=image3)
# make canvas the size of image1/photo1
width1 = photo1.width()
height1 = photo1.height()
canvas1 = Canvas(width=width1, height=height1)
canvas1.pack()
# display photo1, x, y is center
x = (width1)/2.0
y = (height1)/2.0
canvas1.create_image(x, y, image=photo1)
# create two buttons to display smaller images
btn1 = Button(root, text="Image2", command=show_image2)
btn1. pack()
btn2 = Button(root, text="Image3", command=show_image3)
btn2. pack()
root.mainloop()
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Offline 1,704 posts
since Aug 2005