TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.34k stars 1.07k forks source link

Using SVG Images in CTk #1907

Open pwall2222 opened 1 year ago

pwall2222 commented 1 year ago

I'm developing a project and I have decided to use some fontawesome icons since they are well known free and specially I don't have to design them my self. After a bit of digging I found tkfontawesome which is a package that includes the fontawesome icons and a simple api that gives back a tksvg image.

Now that we have that tksvg image, if we use it directly on a CTk element, CTkBaseClass will complaint that image is not of type CTkImage over at

def _check_image_type(self, image: any):
    """ check image type when passed to widget """
    if image is None:
        return image
    elif isinstance(image, CTkImage):
        return image
    else:
        warnings.warn(f"{type(self).__name__} Warning: Given image is not CTkImage but {type(image)}. Image can not be scaled on HighDPI displays, use CTkImage instead.\n")
        return image

But if we use it by wrapping it on a CTkImage it will complain as CTkImage only accepts PIL images, and well PIL doesn't support SVG, and tksvg != PIL.

The quick bodge for fixing this is just using capture warning before using the image, but I'd prefer getting some real support from CTk for displaying SVG images.

pwall2222 commented 1 year ago

Check image type permalink

avalon60 commented 1 year ago

Have you managed to successfully install tkfontawesome? It looks like the project was abandoned and now doesn't appear to install correctly (I raised an issue against the project).

It used to work on Windows, but no more, which is a shame, because in my opinion, it's a game changer in respect of icons and when working with a variety of themes/colours.