【发布时间】:2015-03-04 18:11:30
【问题描述】:
我在 tkinter 中更新画布中的图片时遇到问题。我正在使用 Python 3.3。
from tkinter import *
class Testi():
def __init__(self):
self.canvas = Canvas(root, width = 800, height = 480)
self.img = PhotoImage(file="title.pgm")
self.imgArea = self.canvas.create_image(0, 0, anchor = NW, image = self.img)
self.canvas.pack()
self.but1 = Button(root, text="press me", command=lambda: self.changeImg())
self.but1.place(x=10, y=500)
def changeImg(self):
newimg = PhotoImage(file="cell.pgm")
self.canvas.itemconfig(self.imgArea, image = newimg)
root = Tk()
root.geometry("800x600")
app = Testi()
root.mainloop()
起初图像是可见的,但按下按钮后,它变成空白。我读过很多类似的问题,但没有一个有任何帮助。
【问题讨论】:
标签: python-3.x tkinter