Tkinter, overlay foreground image on top of a background image with transparency

前端 未结 1 1348
后悔当初
后悔当初 2021-01-19 18:34

I have 2 images, in png format. The second image, is a shape with transparent background.

First image:

相关标签:
1条回答
  • 2021-01-19 18:49

    Thanks Bryan. Got it, in addition to label, the issue of transparency resolved from another question here (same foregound image used as a mask)

    I guess, this is what cost me -2 points :-|

    Now it works as expected.

    from Tkinter import *
    import Tkinter
    from PIL import Image, ImageTk
    
    root = Tkinter.Tk()  # A root window for displaying objects
    # open image
    imageHead = Image.open('head.png')
    imageHand = Image.open('hand.png')
    
    imageHead.paste(imageHand, (20, 40), imageHand)
    # Convert the Image object into a TkPhoto object
    tkimage = ImageTk.PhotoImage(imageHead)
    
    panel1 = Label(root, image=tkimage)
    panel1.grid(row=0, column=2, sticky=E)
    root.mainloop()  # Start the GUI
    
    0 讨论(0)
提交回复
热议问题