0
如下所示,我想使用tkinter在畫布上顯示圖像,當點擊按鈕時,應該顯示其他照片。但我失敗了。第一張圖片顯示效果不錯,但當單擊按鈕時,圖片沒有變化如何更改畫布中的圖像?[python tkinter]
C = Tkinter.Canvas(top, bg="#fff", height=500, width=600)
// show image1 in canvas first and it works
itk = ImageTk.PhotoImage(img1)
C.create_image(300, 250, image=itk)
C.pack()
def changeImage():
// I want to show image2 in canvas, but I fails
print 'change image in canvas'
itk2 = ImageTk.PhotoImage(img2)
C.create_image(300, 250, image=itk2)
button = Tkinter.Button(top,text='click', command=changeImage)
button.pack()
top.mainloop()
對不起,我添加後不起作用 – user2666750 2014-10-27 12:50:04