Tkinter.PhotoImage doesn't not support png image

前端 未结 6 855
礼貌的吻别
礼貌的吻别 2020-11-27 08:51

I am using Tkinter to write a GUI and want to display a png file in a Tkiner.Label. So I have some code like this:

self.vcode.img = PhotoImage(d         


        
6条回答
  •  庸人自扰
    2020-11-27 08:59

    try with PIL library instead of converting your image to GIF, PGM, or PPM (PhotoImage) only accept these 3 formats.

    import tkinter as tk
    import PIL.Image
    import PIL.ImageTk
    
    base = tk.Tk()
    base.title("Dialy Dose")
    
    logoPath = r"C:\Users\saigopi\Downloads\logo.png"
    
    ref = PIL.Image.open(logoPath)
    photo = PIL.ImageTk.PhotoImage(im)
    
    inputEdit = tk.Label(base,text="Enter Quote")
    save = tk.Button(base,text="Save",background="green",command=save())
    logo = tk.Label(base,image=photo,text="Logo bro lite")
    quote = tk.Label(base,text="I am saying you are more than something")
    
    inputEdit.pack()
    save.pack()
    logo.pack()
    quote.pack()
    
    base.mainloop()
    

提交回复
热议问题