我正在尝试导入图像并将其设置为标签,但是当我这样做时,我收到错误。有人知道怎么修这个东西吗? (我为图片尝试了很多不同的文件格式,但它有用)
错误 - _tkinter.TclError:无法识别图像文件“pic.png”中的数据
感谢
我的代码:
from tkinter import *
root = Tk()
c = Canvas(root, width = 500, height = 500, highlightthickness = 0)
c.grid(row = 0, column = 0)
oval = c.create_oval(0, 0, 1, 1)
r = 2
def update():
global r, oval
if r < 500:
r += 5
else:
b.destroy()
c.delete(oval)
oval = c.create_oval(0, 0, r, r)
root.after(50, update)
b = Button(text = "123", command = update, cursor = "iron_cross")
b.grid(row = 1, column = 0)
z = PhotoImage(file='pic.png')
label = Label(image = z)
label.grid(row = 2, column = 0)
root.mainloop()
答案 0 :(得分:1)