TomSchimansky / CustomTkinter

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

Transparent Window #2376

Closed Sayad-Uddin-Tahsin closed 2 months ago

Sayad-Uddin-Tahsin commented 2 months ago

Is there any way to have the main window background to be transparent and the frame(s), labels in a word other component will work in normal way?

Akascape commented 2 months ago

@Sayad-Uddin-Tahsin

Transparency is only possible in windows/mac:

import sys

if sys.platform.startswith("win"):
            self.transparent_color = self._apply_appearance_mode(self.cget("fg_color")) # You can use any other color
            self.attributes("-transparentcolor", self.transparent_color)
elif sys.platform.startswith("darwin"):
            self.transparent_color = 'systemTransparent'
            self.attributes("-transparent", True)
else:
            self.transparent_color = '#000001'

Then use self.transparent_color in the background of widget to make the area transparent

Sayad-Uddin-Tahsin commented 2 months ago
self.transparent_color = self._apply_appearance_mode(self.cget("fg_color"))

Seems this solution slightly breaks if we change the theme while running the program, is there anyway to detect theme change? like an event? @Akascape