Tkinter, overlay foreground image on top of a background image with transparency
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 Tkinterfrom PIL import Image, ImageTkroot = Tkinter.Tk() # A root window for displaying objects# open imageimageHead = Image.open('head.png')imageHand = Image.open('hand.png')imageHead.paste(imageHand, (20, 40), imageHand)# Convert the Image object into a TkPhoto objecttkimage = ImageTk.PhotoImage(imageHead)panel1 = Label(root, image=tkimage)panel1.grid(row=0, column=2, sticky=E)root.mainloop() # Start the GUI
Hey guys I know that I am 6 years late but I can help you with this
from PIL import Imageimport numpy as np# Create Imageimg = Image.open("forground.png")background = Image.open("background.png")background.paste(img, (0, 0), img)background.save('NewImg.png',"PNG")NewImg = Image.open('NewImg.png')# Use Imagetkimage = ImageTk.PhotoImage(NewImg)panel1 = Label(root, image=tkimage)panel1.grid(row=0, column=2, sticky=E)root.mainloop() # Start the GUI
So all you have to do is use NewImg when dealing with the file.This code creates an image out of the two images and then utilises that image in the program.