【发布时间】:2018-11-28 10:54:00
【问题描述】:
我尝试使用以下代码打开照片,但没有成功,它说文件不存在,并且都在同一个文件夹中,我环顾四周,但似乎没有任何效果
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()
【问题讨论】:
-
您可能需要将文件的扩展名添加到
file=参数。默认情况下,某些操作系统会对您隐藏这一点。例如,在 WINdows 上有一个“Hide extensions for known file types”的文件夹选项。看看你能不能禁用它,这样你才能看到它们。