Skip to main content

Apply mica background (if supported) and immersive dark mode to Windows 11 Win32 apps made with python, such as Tkinter or PyQt/PySide apps

Project description

Win32mica: A simple module to add the Mica effect and enable immersive dark mode on Python UI Windows

The aim of this project is to apply the Mica effect and enable immersive dark mode on python applications made with Python, like Tkinter, PyQt/PySide, WxPython, Kivy, etc.
This will work on any windows version, including the new released dev builds where the mica API is public.

View this project on PyPi View this project on GitHub

Installation:

python -m pip install win32mica

Requirements:

  • Windows 11
  • A window set to not have a transparent background and to have extended composition enabled* (It might work with other settings, but nothing is guaranteed.)
  • The HWND (identifier) of that window. More info: what is a hwnd?
  • OPTIONAL: The window must have semi-transparent widgets/controls in order to recreate the transparency effect on the controls.
  • OPTIONAL: Know if Windows has dark or light mode enabled. This can be checked with the darkdetect module

Usage:

#####################################################################
#                                                                   #
# Those examples are oversimplified, please see the examples folder #
# for detailed usage with each UI library.                          #
#                                                                   #
#####################################################################

hwnd = qtwindow.winId().__int__() # On a PyQt/PySide window
hwnd = tkwindow.frame() # On a tkinter window
# You'll need to adjust this to your program

from win32mica import MICAMODE, ApplyMica

mode = MICAMODE.DARK  # Dark mode mica effect
mode = MICAMODE.LIGHT # Light mode mica effect
# Choose one of them following your app color scheme

import darkdetect # You can pass the darkdetect return value directly, since the ColorMode accepts bool values (True -> dark, False -> light)
mode = darkdetect.isDark()

win32mica.ApplyMica(hwnd, mode)
# Will return 0x32 if the system does not support Mica textures (Windows 10 or less). Immersive dark mode will still be applied (if selected theme is MICAMODE.DARK)
# Will return 0x00 if mica is applied successfully
# If DwmSetWindowAttribute fails, the output code will be returned 

You can check out the examples folder for detailed use in Tk and PySide/PyQt.

Result:

image
image

Those are PySide2 windows with custom widgets.

Troubleshooting:

For more information about possible errors/mistakes, make sure to add the following before using win32mica:

# Add these lines at the very start of your script
import win32mica
win32mica.debugging = True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

win32mica-1.9.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

win32mica-1.9-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file win32mica-1.9.tar.gz.

File metadata

  • Download URL: win32mica-1.9.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for win32mica-1.9.tar.gz
Algorithm Hash digest
SHA256 46beff36c9e27c67bdd5d4a7f32ac7ed8277cc42a0613d4492d0cf304fe5135d
MD5 606a44c8cf11611e8d49c08aae4996e2
BLAKE2b-256 f1c32341aacb9f41255d3c6dcf28fb919c1a3ed23e08de7b2b0b16d0fc26d309

See more details on using hashes here.

File details

Details for the file win32mica-1.9-py3-none-any.whl.

File metadata

  • Download URL: win32mica-1.9-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for win32mica-1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d832e0a4ba3a2c8e586d92ca22c9b089615aed9a39e58811f07684d6a45fd13a
MD5 fe7487ced816832ea7db1f3561243756
BLAKE2b-256 203abee0d277084007da2fffba73e727fa17953e1fd515c3de41f6bf289ecb1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page