Im trying to make a game engine with tkinter but I've encountered a problem. I have an image when opened, clearly shows transparency and, when this code is run:
print(image.mode)
it prints RGBA as the mode. I have googled the necessary elements for transparent images on tkinter and I have all of it. Mode=RGBA format=PNG and yet, it's still not completely transparent:
and here's the image when opened on preview. It clearly shows transparency:
So why does it show transparency in preview and other apps(like google docs, slides, etc.) but doesn't show transparency in tkinter?
heres the full code:
from tkinter import *
from PIL import ImageTk, Image
class Create(object):
def __init__(self, root, img="default.png", width=None, height=None, x=0, y=0):
self._debug_img = Image.open(img)
self.img = ImageTk.PhotoImage(Image.open(img))
self.img_wdth, self.img_hgt = self._debug_img.size
if width == None and height == None:
self.width = self.img_wdth
self.height = self.img_hgt
elif type(width) != int and type(height) != int:
self.width = self.img_wdth
self.height = self.img_hgt
elif width != self.img_wdth and height != self.img_hgt:
self.copy = self._debug_img.resize((self.width, self.height))
self.img = ImageTk.PhotoImage(Image.open(self.copy))
self.hitbox = (width, height)
self.x = x
self.y = y
self.root = root
self.sprite = Label(self.root, image=self.img)
self.sprite.place(x=self.x, y=self.y, anchor=CENTER)
def update_pos(self):
self.sprite.place(x=self.x, y=self.y)
def update_sprite(self):
self.copy = ImageTk.PhotoImage(Image.open(Image.open(self.img).resize(self.width, self.height)))
self.sprite = Label(self.root, image=self.copy)
def update_hitbox(self):
self.hitbox = (self.width, self.height)