You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While it may deviate from the core philosophy of Flet building, the integration of a darkened title bar, a standard feature within Windows, notably in Windows 11, is within the realm of possibility for developers. This functionality holds the potential to attract a broader audience, particularly among fervent Windows enthusiasts. In the context of Tkinter, specifically customtkinter, as well as other versatile GUI libraries and the C++ development environment for Windows, various mechanisms exist to facilitate the darkening of the title bar.
In customtkinter, and other same libraries can make the title bar dark using following appropriate approach:
def_windows_set_titlebar_color(self, color_mode: str):
""" Set the titlebar color of the window to light or dark theme on Microsoft Windows. Credits for this function: https://stackoverflow.com/questions/23836000/can-i-change-the-title-bar-in-tkinter/70724666#70724666 MORE INFO: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute """ifsys.platform.startswith("win") andnotself._deactivate_windows_window_header_manipulation:
ifself._window_exists:
self._state_before_windows_set_titlebar_color=self.state()
# print("window_exists -> state_before_windows_set_titlebar_color: ", self.state_before_windows_set_titlebar_color)ifself._state_before_windows_set_titlebar_color!="iconic"orself._state_before_windows_set_titlebar_color!="withdrawn":
self.focused_widget_before_widthdraw=self.focus_get()
super().withdraw() # hide window so that it can be redrawn after the titlebar change so that the color change is visibleelse:
# print("window dont exists -> withdraw and update")self.focused_widget_before_widthdraw=self.focus_get()
super().withdraw()
super().update()
ifcolor_mode.lower() =="dark":
value=1elifcolor_mode.lower() =="light":
value=0else:
returntry:
hwnd=ctypes.windll.user32.GetParent(self.winfo_id())
DWMWA_USE_IMMERSIVE_DARK_MODE=20DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1=19# try with DWMWA_USE_IMMERSIVE_DARK_MODEifctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE,
ctypes.byref(ctypes.c_int(value)),
ctypes.sizeof(ctypes.c_int(value))) !=0:
# try with DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20h1ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1,
ctypes.byref(ctypes.c_int(value)),
ctypes.sizeof(ctypes.c_int(value)))
exceptExceptionaserr:
print(err)
ifself._window_existsorTrue:
# print("window_exists -> return to original state: ", self.state_before_windows_set_titlebar_color)ifself._state_before_windows_set_titlebar_color=="normal":
self.deiconify()
elifself._state_before_windows_set_titlebar_color=="iconic":
self.iconify()
elifself._state_before_windows_set_titlebar_color=="zoomed":
self.state("zoomed")
else:
self.state(self._state_before_windows_set_titlebar_color) # other stateselse:
pass# wait for update or mainloop to be calledifself.focused_widget_before_widthdrawisnotNone:
self.after(1, self.focused_widget_before_widthdraw.focus)
self.focused_widget_before_widthdraw=None
The text was updated successfully, but these errors were encountered:
While it may deviate from the core philosophy of Flet building, the integration of a darkened title bar, a standard feature within Windows, notably in Windows 11, is within the realm of possibility for developers. This functionality holds the potential to attract a broader audience, particularly among fervent Windows enthusiasts. In the context of Tkinter, specifically
customtkinter
, as well as other versatile GUI libraries and the C++ development environment for Windows, various mechanisms exist to facilitate the darkening of the title bar.In customtkinter, and other same libraries can make the title bar dark using following appropriate approach:
The text was updated successfully, but these errors were encountered: