3

Estou com um problema ao tentar sobrepor uma imagem já existente no 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()
1
  • Mesmo que eu coloque a imagem em posiçao diferente da outra a imagem n aparece em si mas ocupa espaço 28/07/2018 às 11:09

1 Resposta 1

2

Bom dia amigo!

Resolvi seu problema aqui de uma maneira bem simples:

Usei apenas um label e quando o botão é clicado, simplesmente alterei a propriedade file do label: head['file'] = "rosto1.png"

Segue o código:

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()

Se puder, testa ai e manda um feedback se resolve o seu problema.

2
  • Cara funcionou sim, mto obrigado msm, nao sabia q podia so altera o caminho no python, vlw msm 29/07/2018 às 12:19
  • 1
    Que bom! Pode alterar qualquer atributo.. 29/07/2018 às 17:05

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .