Note on applying Acrylic themes
mainacrylic theme, it is recommended to paint your UI window with a black color to ensure the effect renders correctly.repository·main·Indexed 20 days ago
https://github.com/akascape/py-window-stylesA Python library for customizing the visual appearance of UI windows on Windows. It provides access to Windows 11 header styles such as Mica and Acrylic, as well as custom coloring for title bars, title text, and borders. The library supports integration with Tkinter, CustomTkinter, PyGame, PyQt, PySide, WxPython, and PySimpleGUI, or any UI library via the window handle (HWND).
acrylic theme, it is recommended to paint your UI window with a black color to ensure the effect renders correctly.For libraries not explicitly supported (like Kivy), you must retrieve the window handle (HWND) and pass it to pywinstyles.
To get the active window handle:
from ctypes import windll
hwnd = windll.user32.GetActiveWindow()To find a window handle by its title:
from ctypes import windll
hwnd = windll.user32.FindWindowW(None, window_name)from ctypes import windll
import pywinstyles
# Get active window handle
hwnd = windll.user32.GetActiveWindow()
# Or find by name
# hwnd = windll.user32.FindWindowW(None, "Window Name")
pywinstyles.change_header_color(hwnd, color="blue")Install the pywinstyles package using pip to start customizing Windows UI windows in your Python applications.
pip install pywinstylesPass the wx.Frame instance to pywinstyles.change_header_color to modify the header color.
import wx
import pywinstyles
app = wx.App()
frame = wx.Frame(parent=None, title='wx-python')
pywinstyles.change_header_color(frame, color="blue")
frame.Show()
app.MainLoop()When using PySimpleGUI, you must access the underlying Tkinter root object via window.TKroot to pass it to pywinstyles. Ensure the window is finalized (using finalize=True) before applying styles.
import PySimpleGUI as sg
import pywinstyles
layout = [[sg.Text("pywinstyles example")], [sg.Button("OK")]]
window = sg.Window("Demo", layout, finalize=True)
pywinstyles.change_header_color(window.TKroot, color="blue")PyGame requires you to manually retrieve the window handle (HWND) before passing it to pywinstyles. You can get the HWND using pygame.display.get_wm_info()["window"].
import pygame
import pywinstyles
screen = pygame.display.set_mode((300, 200))
hwnd = pygame.display.get_wm_info()["window"]
pywinstyles.change_header_color(hwnd, color="blue")For PyQt (e.g., PyQt5) or PySide (e.g., PySide2), pass the window object directly to pywinstyles.change_header_color.
# PyQt5 Example
import sys
from PyQt5 import QtWidgets
import pywinstyles
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
pywinstyles.change_header_color(window, color="blue")
window.show()To change the header color of a Tkinter or CustomTkinter window, pass the window instance (root) to pywinstyles.change_header_color and specify the color argument.
import tkinter
import pywinstyles
root = tkinter.Tk()
pywinstyles.change_header_color(root, color="blue")
root.mainloop()If you are running on Windows 11, you can customize specific window elements using the following methods:
pywinstyles.change_header_color(window, color="#HEX")pywinstyles.change_title_color(window, color="color_name_or_hex")pywinstyles.change_border_color(window, color="#HEX")pywinstyles.get_accent_color() returns the current system accent color as a hex string.import pywinstyles
# Change title bar to a specific hex color
pywinstyles.change_header_color(window, color="#00524d")
# Change title text to white
pywinstyles.change_title_color(window, color="white")
# Change border color
pywinstyles.change_border_color(window, color="#00ffff")
# Retrieve system accent color
accent = pywinstyles.get_accent_color()Use pywinstyles.apply_style(window, style) to apply built-in Windows 11 header styles or Windows 10 themes to your window.
Supported Styles:
mica: Windows 11 Mica effect.acrylic: Windows 11 Acrylic effect.aero: Aero effect (GPU Heavy).transparent: Transparent effect (GPU Heavy).optimised: Optimized style.win7: Windows 7 style.inverse: Inverse style.native: Native window style.popup: Popup style.dark: Dark mode style.normal: Resets to no change.import pywinstyles
# window is your UI library's window object (Tkinter, PyQt, etc.)
pywinstyles.apply_style(window, 'mica')You can control the visibility of individual widgets using pywinstyles.set_opacity.
0.0 and 1.0 to value.