这是让我发疯的代码:
from tkinter import*
import os.path
class About:
def __init__(self):
font1='tahoma 12'
win=Tk()
print(os.path.isfile('logo.gif'))#It returns true
Label(win,image="logo.gif").pack()
About()
最佳答案
Label(win,image="logo.gif").pack()
image
参数不接受文件名。根据this教程,“该值应该是 PhotoImage、BitmapImage 或兼容对象。”接下来讨论您应该使用的 PhotoImage
类。
You can use the label to display PhotoImage and BitmapImage objects. When doing this, make sure you keep a reference to the image object, to prevent it from being garbage collected by Python’s memory allocator. You can use a global variable or an instance attribute, or easier, just add an attribute to the widget instance:
photo = PhotoImage(file="icon.gif")
w = Label(parent, image=photo)
w.photo = photo
w.pack()
关于Python 标签图像不存在,但 os.path 说它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23524615/