0

i wrote this code on the school computer, and it was totally fine. i wrote the same code on my personal pc and now it shows the picture with no transparency (with black background). the picture is the same picture(a png with no background)

from tkinter import *
from PIL import ImageTk, Image
root = Tk()
root.geometry("1300x731")
root.resizable(width=False, height=False)
photo = Image.open("logo.png")
zoom = 0.5
pixels_x, pixels_y = tuple([int(zoom * x)  for x in photo.size])
img = ImageTk.PhotoImage(photo.resize((pixels_x, pixels_y)))
panel = Label(root, image = img).place(relx = 0.5, rely = 0.1, anchor = 'center')
#panel.grid(row=5000, column=3)
#panel.pack(side = "bottom", fill = "both", expand = "yes")


root.config(cursor="@curs.cur")
while True:
    root.mainloop()
Nir Cohen
  • 11
  • 1
  • you can use a generator expression to get a tuple instead of list comprehension, also only `Canvas` support transparency. also don't use `*` when importing – Matiiss Dec 01 '21 at 15:21
  • Why do you put `root.mainloop()` in a infinite while loop? BTW you should see gray background (default background color of a label) if the PNG has transparency. – acw1668 Dec 01 '21 at 15:31
  • PNG file not means all with transparency, it depends the alpha layer. Maybe your logo.png is not transparent. – Jason Yang Dec 04 '21 at 07:26

1 Answers1

0

try it with another import method.

use photo = PhotoImage(file="logo.png")

this should remove the black background.

  • Remove the "while True:"

root.mainloop() is a loop by itself

Basti
  • 1