tkinter PhotoImage doesn't exist?

前端 未结 2 321
栀梦
栀梦 2021-01-20 03:49
from tkinter import *

root = Tk()

photo = PhotoImage(file=\'blueface.png\')
label = Label(root, image=photo)
label.pack()

root.mainloop()

The im

2条回答
  •  醉话见心
    2021-01-20 04:30

    Older versions of tkinter can not handle .png's that well. Try making the file a .gif. Or use the PhotoImage from PIL:

    import tkinter as tk
    from PIL import Image, ImageTk
    
    root = tk.Tk()
    
    photo = ImageTk.PhotoImage(Image.open('blueface.png'))
    label = tk.Label(root, image=photo)
    label.pack()
    
    root.mainloop()
    

提交回复
热议问题