How to Make PNG Remain Transparent in Tkinter?

26 Views Asked by At

I am working on a drag and drop python project where I can drag and drop around multiple sprites in a Tkinter window. However I am facing a problem where the sprites are not transparent even though they are PNGs and I made sure that the background was transparents. For somereason I don't know, when dragging around the sprites the background will oclude other sprites in white becuase it is rendering th sprite with a white background.

This is the current portion of the code I have that handles rendering and everything else works apart from the transparency of the image.

for i, image_number in enumerate(RedPlayerImageNumbers):
    RedPlayerImageRef = RedPlayerImageLink + image_number
    pil_image = Image.open(RedPlayerImageRef).convert("RGBA")
    RedPlayerImage = ImageTk.PhotoImage(pil_image)
    player_images.append(RedPlayerImage)

    canvas = Canvas(win, width=pil_image.width, height=pil_image.height)
    canvas.create_image(0, 0, image=RedPlayerImage, anchor="nw")
    canvas.place(x=RedPlayerImageCords[i][0], y=RedPlayerImageCords[i][1])

    canvas.bind("<Button-1>", DragStart)
    canvas.bind("<B1-Motion>", DragMotion)

0

There are 0 best solutions below