Tkinter Image transparency

前端 未结 2 1343
故里飘歌
故里飘歌 2020-12-04 00:33

So I have 2 images that I would like to display on top of each other. The image on top should have transparency so that the one on the bottom is visible.

Here is my

2条回答
  •  心在旅途
    2020-12-04 00:57

    Try this

    from PIL import Image, ImageTk
    from Tkinter import Tk, Label
    
    root = Tk()
    
    def RBGAImage(path):
        return Image.open(path).convert("RGBA")
    
    face = RBGAImage("faces/face.gif")
    eyes = RBGAImage("faces/eyes1.png")
    
    face.paste(eyes, (0, 0), eyes)
    
    facepic = ImageTk.PhotoImage(face)
    
    label1 = Label(image=facepic)
    label1.grid(row = 0, column = 0)
    
    root.mainloop()
    

    I do not have both your source images, so I can not be sure it will work with them. Please provide the originals of both if there is any issue.

提交回复
热议问题