Win32mica: a simple module to add the Mica effect on legacy python windows.

Overview

Win32mica (aka PyMica): A simple module to add the Mica effect on legacy python windows

The aim of this project is to apply the Mica effect on python applications made with Python, like Tkinter, PyQt/PySide, WxPython, Kivy, etc.

View this project also on PyPi

Installation:

python -m pip install win32mica

Requirements:

  • Windows 11
  • A frameless window (It might work with a normal window, bit it is not guaranteed.)
  • The HWND (identifier) of that window. More info: what is a hwnd?
  • The window must have semi-transparent widgets/controls in order to recreate the transparency effect.
  • Know if Windows has dark or light mode enabled. This can be checked with the darkdetect module

Usage:

hwnd = qtwindow.winId() # 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

import darkdetect # Auto mode detect
mode = darkdetect.isDark()

win32mica.ApplyMica(hwnd, mode)

Result:

Demo
This is a PySide2 window with custom transparent widgets. The screenshot has been taken on dark mode.

Comments
  • Error when applying mica

    Error when applying mica

    Hi! Reallay awsome project! I get this error when running on tkinter window: Code: ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=True) Error:

      File "D:\Coding\TimerX\main.py", line 783, in makeWindowsBlur
        ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=True)
      File "C:\Users\suchi\AppData\Local\Programs\Python\Python310\lib\site-packages\win32mica\__init__.py", line 54, in ApplyMica        
        SetWindowCompositionAttribute(HWND, Wca)
    ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected WINDOWCOMPOSITIONATTRIBDATA instance instead of WindowCompositionAttribute
    
    opened by sumeshir26 11
  • Compiling with cx_Freeze

    Compiling with cx_Freeze

    Hello! I am using win32mica in a program, and when running the program from the .py file, everything works flawlessly. But when i compile the program to an execuetable using cx_Freeze, win32mica throws the following error:

    Win32Mica Error: win32 version 9200 is not supported

    What does that mean and how do i fix it?

    opened by not-nef 8
  • Change the ColorMode=MICAMODE.LIGHT but it's still dark!

    Change the ColorMode=MICAMODE.LIGHT but it's still dark!

    Not sure if I did something wrong My code:

    def Light():
        app.tk.call("ttk::style", "theme", "use") == "sun-valley-dark"
        app.tk.call("set_theme", "light")
        bg_color = ttk.Style().lookup(".", "background")
        app.wm_attributes("-transparent", bg_color)
        HWND=windll.user32.GetParent(app.winfo_id())
        ApplyMica(HWND, ColorMode=MICAMODE.LIGHT)
        app.update()
    
    def Dark():
        app.tk.call("ttk::style", "theme", "use") == "sun-valley-dark"
        app.tk.call("set_theme", "dark")
        bg_color = ttk.Style().lookup(".", "background")
        app.wm_attributes("-transparent", bg_color)
        HWND=windll.user32.GetParent(app.winfo_id())
        ApplyMica(HWND, ColorMode=MICAMODE.DARK)
        app.update()
    

    Result:

    https://user-images.githubusercontent.com/86362423/156988497-26c5d22c-f3fa-4148-ae41-890c3842c24a.mp4

    opened by HuyHung1408 7
  • ValueError: invalid literal for int() with base 10: '0xa20856'

    ValueError: invalid literal for int() with base 10: '0xa20856'

    My code is:

    import tkinter
    from tkinter import ttk
    
    import sv_ttk
    root = tkinter.Tk()
    root.geometry('400x100+200+200') # set new geometry
    from win32mica import MICAMODE, ApplyMica
    import darkdetect # You can pass the darkdetect return value directly, since the ColorMode accepts bool values (True -> dark, False -> light)
    mode = darkdetect.isDark()
    
    hwnd = root.frame() # On a tkinter window
    ApplyMica(hwnd, mode)
    
    button = ttk.Button(root, text="Click me!")
    button.pack()
    
    
    # This is where the magic happens
    if darkdetect.isDark():
      sv_ttk.set_theme("dark")
    else:
      sv_ttk.set_theme("light")
    
    root.mainloop()
    

    Applying Win32Mica messed it up.

    Is it a bug in Win32Mica, or a bug in my code?

    EDIT: Here is the backlog appearing when running the script:

    Traceback (most recent call last):
      File "C:\Users\tyler\fluent-tkinter.py", line 12, in <module>
        ApplyMica(hwnd, mode)
      File "C:\Users\tyler\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32mica\__init__.py", line 18, in ApplyMica
        HWND = int(HWND)
    ValueError: invalid literal for int() with base 10: '0xa20856'
    
    opened by TylerMS887 6
  • Issue in focus

    Issue in focus

    By clicking on the part where mica is used, the program minimizes. If the topmost attribute is applied, the window loses focus, and the mica effect is no longer visible.

    opened by jaivardhan-bhola 6
  • Everything works but the I cannot close the thing after restoring a minimised window

    Everything works but the I cannot close the thing after restoring a minimised window

    I made a tkinter application which uses this beautiful mica style, and everything worked. The mica applies fine, there are no errors related to HWND, but there is this one issue. When I restore a minimised window, there are no hitboxes for any buttons on the titlebar. This isssue is related to #7 where OP was not able to focus his window. The same thing happens here, but the only clickable buttons are the ones I made by myself in python, the close, maximise and minimise buttons don't really work

    From #7 , I found out that this issue was a tkinter one, is it the case here too?

    yes

    From this gif, I was trying to click the minimise button again, but the click is registered on the desktop instead of the app itself

    opened by SlavBoi420 5
  • Can't change mica theme without reopening app.

    Can't change mica theme without reopening app.

    while using this i noticed that when you want to change the mica effect whilst the app was open, you could only change from light to dark, but not back.

    https://user-images.githubusercontent.com/97522577/188254033-d63b16d9-9641-4a67-b61c-c3d8564d6eef.mp4

    opened by Cowski0 3
Releases(1.7.1)
Delphi's FireMonkey framework as a Python module for Windows, MacOS, Linux, and Android GUI development.

DelphiFMX4Python Delphi's FireMonkey framework as a Python module for Windows, MacOS, Linux, and Android GUI development. About: The delphifmx library

Embarcadero Technologies 191 Jan 9, 2023
Custom GUI for your Blender add-ons using Dear ImGui

Dear Imgui for Blender Use the infamous Dear ImGui library directly in your Blender scripts! This means custom GUI drawing in your operators: Normally

Elie Michel 83 Dec 25, 2022
A simple GUI designer for the python tkinter module

Leer en Español Welcome to Pygubu! Pygubu is a RAD tool to enable quick and easy development of user interfaces for the Python's tkinter module. The u

Alejandro Autalán 1.7k Dec 27, 2022
Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

Kivy Innovative user interfaces made easy. Kivy is an open source, cross-platform Python framework for the development of applications that make use o

Kivy 15.4k Jan 7, 2023
A small pomodoro GUI for Windows/Linux created in Python with PyQt5.

Pomodoro A small pomodoro GUI for Windows/Linux created with PyQt5. Features The "Timer" tab allows you to set your desired work and rest times aswell

Burak Martin 81 Dec 28, 2022
Create shortcuts on Windows to your Python, EXE, Batch files or any other file using a GUI made with PySimpleGUI

shor Windows Shortcut Creation Create Windows Shortcuts to your python programs and any other file easily using this application created using PySimpl

PySimpleGUI 7 Nov 16, 2021
A python Script For Taking Screenshot Of Windows

PyShot A Python Script For Taking Screenshot Of Windows Disclaimer This tool is for educational purposes only ! Don't use this to take revenge I will

Nazim Cp 2 Jun 22, 2022
A Windows Dock Widget Written In Pure Python

VEПUS A Windows Dock Widget Written In Pure Python What is Venus? Venus is a Dock Widget for your desktops interface. It adds a couple of really cool

Secrets 18 Dec 30, 2022
A simple project used Tkinter module to make a seperate window

Project Title This is a program to run a databse where you can store the general information of poeple. This is a very simple project and i have used

Divyansh Bhardwaj 0 Jun 25, 2022
A Minimalistic Backup GUI for your Windows, Mac or Linux

BlobBackup is a minimalistic backup utility for your Windows, Mac or Linux computer. With an excellent engine, extensive storage support, and an easy

Bimba Shrestha 283 Nov 30, 2022
A Minimalistic Backup GUI for your Windows, Mac or Linux

BlobBackup is a minimalistic backup utility for your Windows, Mac or Linux computer. With an excellent engine, extensive storage support, and an easy

null 283 Nov 30, 2022
Desktop application for Windows/macOS users to rotate through custom, preset, and searched-for collections of backgrounds with scheduling and additional settings

Background Revolution (In Development, Alpha Release) What? This will be an application for users to customize their windows backgrounds by uploading

Daniel Agapov 1 Nov 2, 2021
A cute running cat animation on your Windows/macOS taskbar.

RunCat by PySide6 A cute running cat animation on your Windows/macOS taskbar. Tags PyQt PySide RunCat Demo You only have to run the RunCat.exe. Run pi

見える 10 Sep 19, 2022
Windows & Linux GUI application to use a Satodime (satodime.io)

Satodime-Tool Licence: LGPL v3 Author: Toporin Language: Python (>= 3.6) Homepage: https://github.com/Toporin/Satodime-Tool Introduction What is Satod

null 4 Dec 16, 2022
Transparent & click through tkinter window. WINDOWS ONLY

REQUIREMENTS: WINDOWS ONLY pip install pywin32 NOTES: Will not work on top of a fullscreen application, if you are using this to draw on top of a gam

francis 2 Nov 4, 2022
A GUI calculator made with tkinter module in python

GUI-Calculator A GUI calculator made with tkinter module in python How to setup the calculator If pygame is not installed, go to terminal and do pip i

Eric Jing 0 Aug 25, 2021
A really minimalistic operating system made using python's GUI module Tkinter.

BoxOS V1.0.0 About A really minimalistic operating system made using python's GUI module Tkinter. What seperates it from the other operating systems m

Fahim 2 Dec 8, 2022
Python Web Version 3.0 Using PyQty module

Python-Web-Version-3.0 Python Web Version 3.0 Using PyQty module you have to install pyinstaller module then install PyQt5 module and install PyQtwebE

JehanKandy 9 Jul 13, 2022