Image overlay on Tkinter

3

I have a problem trying to overlay an existing image in Python 3.

from tkinter import *
jan = Tk()
jan.geometry("500x500")
jan.configure(background="#f0f0f0")

head = PhotoImage(file = "rosto0.png")
label = Label(jan, image = head)
label.place(x=100 , y=10)

def crt():
   head2 = PhotoImage(file = "rosto1.png")
   lbl = Label(jan, image = head2)
   lbl.place(x=100 , y=10)

crt = Button(jan, text="TROCAR ROSTO", font=("Centurty Gothic",10), 
command=crt)
crt.place(x=5, y=10)

jan.mainloop()
    
asked by anonymous 28.07.2018 / 13:07

1 answer

2

Good morning, my friend!

I solved your problem here in a very simple way:

I used only one label and when the button was clicked, I simply changed the file property of the label: head['file'] = "rosto1.png"

Follow the code:

from tkinter import *

jan = Tk()
jan.geometry("500x500")
jan.configure(background="#f0f0f0")

head = PhotoImage(file = "rosto0.png")
label = Label(jan, image = head)
label.place(x=100 , y=10)


def crt():
   head['file'] = "rosto1.png"


crt = Button(jan, text="TROCAR ROSTO", font=("Centurty Gothic",10), command=crt)
crt.place(x=5, y=10)

jan.mainloop()

If you can, test there and send feedback if it solves your problem.

    
28.07.2018 / 14:53