Remove image background with Tkinter

Asked

Viewed 396 times

2

I’m trying to make two layers with two images in which the background is whole in the application, and the second overlaps. The second is transparent, however, when the display occurs, it puts gray background. How can I take this background?

from tkinter import *
import time
janela = Tk()

janela.geometry("1920x1080")
janela.title("Mario")

mario = PhotoImage(file = "cenario.png")

label = Label(janela, image = mario).place(x=0,y=0)
photo = PhotoImage(file = "mario.png")
label = Label(janela, image = photo).place(x=3,y=600)

janela.mainloop()

inserir a descrição da imagem aqui

  • 1

    You can take a look at the canvas widget, there are ways to create a label delimited with it, drawn type. Look at this link here too.

  • I looked at the link, and from what I understood I need to create a canvas and put the image on top, but I’m not able to create the code, and I can’t find one. Could show an example code?

1 answer

0

The only way I know for the images to have a transparent background is to make them canvas...

from tkinter import *

j = Tk()
canvas = Canvas(j,  bd=0, highlightthickness=0)
canvas.pack()

image = PhotoImage(file='foto1.png')
image_id2 = canvas.create_image(25,25, image=image)

image2 = PhotoImage(file='foto2.png')
image_id = canvas.create_image(25,60, image=image2)

j.mainloop()

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.