请看一下这段代码。
#normal template stuff
from Tkinter import *
from PIL import Image, ImageTk
win=Tk()
win.geometry('+0+0')
win.title(" Borderlands 2 Chicks")
#How to add intro photo
img = Image.open("intro.gif")
intro = ImageTk.PhotoImage(img)
right = Label(win, image=intro)
right.grid(row=0, column=1, rowspan=5)
#defernitions to call photos
def but1():
img = Image.open("captain_scarlett.gif")
intro = ImageTk.PhotoImage(img)
right1 = Label(win, image=intro)
right1.grid(row=0, column=1, rowspan=5,)
def but2():
img = Image.open("Ellie.gif")
intro = ImageTk.PhotoImage(img)
right = Label(win, image=intro)
right.grid(row=0, column=1, rowspan=5)
def but3():
img = Image.open("Gaige Swin Suit.gif")
intro = ImageTk.PhotoImage(img)
right = Label(win, image=intro)
right.grid(row=0, column=1, rowspan=5)
def but4():
img = Image.open("Gaige.gif")
intro = ImageTk.PhotoImage(img)
right = Label(win, image=intro)
right.grid(row=0, column=1, rowspan=5)
#buttons on the left column
left1 = Button(win, text=" Captian Scarlet")
left1.configure(command=but1)
left2 = Button(win, text=" Button 2 ")
left2.configure(command=but2)
left3 = Button(win, text=" Button 3 ")
left3.configure(command=but3)
left4 = Button(win, text=" Button 4 ")
left4.configure(command=but4)
left1.grid(row=0, column=0)
left2.grid(row=2, column=0)
left3.grid(row=3, column=0)
left4.grid(row=4, column=0)
#how to get buttons to do something
def but1(): print "Button one was pushed"
mainloop()
这个应用程序起初显示良好。我按下第一个按钮,右栏变成白色。我需要的是在我按下任何按钮后替换右栏中当前照片的代码。我一直在学习Destroy()
,grid_forget()
但我找不到适用于这个应用程序的示例代码。请帮忙。