Tkinter.PhotoImage doesn't not support png image

前端 未结 6 850
礼貌的吻别
礼貌的吻别 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 09:15

    from tkinter import *
    from tkinter import messagebox
    import os
    from PIL import Image, ImageTk
    
    
    root = Tk()
    root.geometry("1300x720")
    root.title("KEDİLERİMİZ ve KÖPEKLERİMİZ")
    class Ana:
        def __init__(self,name,roll):
            self.name = name
            self.roll = roll
    resim = Label(root,width=77,height=43,bg="blue")
    resim.place(x=730,y=10)
    o = "1.PNG"
    hu = o.find(".")
    mu = o[hu:]
    if mu == ".gif" or mu == ".png":
        img = PhotoImage(file = o)
    else:
        photo = Image.open(o)
        img = ImageTk.PhotoImage(photo)
    resim.configure(image=img,width=img.width(),height=img.height())
    resim.image = img
    

提交回复
热议问题