我尝试使用以下代码打开照片,但没有运气,它说该文件不存在,并且都在同一文件夹中,我环顾四周,但似乎没有任何作用
from tkinter import *
import sys
from random import *
def button1():
novi = Toplevel()
canvas = Canvas ( novi , width = 300, height = 200 )
canvas.pack(expand = YES, fill = BOTH)
gif1 = PhotoImage (file = 'hey')
canvas.create_image (50, 10, image = gif1, anchor = NW)
cancas.gif1 = gift1
mGui = Tk()
button1 = Button(mGui, text = 'hey boiz',command = button1, height = 5 , width = 20).pack()
mGui.mainloop()
答案 0 :(得分:0)
您忘记了文件类型为png
还是jpg
gif1 = PhotoImage (file = 'hey')
更改为gif1 = PhotoImage (file = 'hey.gif')
答案 1 :(得分:0)
别忘了文件类型。
gif1 = PhotoImage(file='hey.png')
编辑:
gif1 = PhotoImage(file='hey.gif')
canvas.create_image (50, 10, image = gif1, anchor = NW)
canvas.gif1 = gif1
更正了您的错别字和我半睡半醒的答案。