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)
FPKG Maker GUI - A user friendly User Interface for fPKG Tools for PS4

Know Issues being worked on Please place this application on the root of a drive

26 Nov 27, 2022
Yasb is a highly configurable and hackable taskbar written in python with Qt6.

Yasb: Yet Another Status Bar Yasb is a highly configurable and hackable taskbar written in python with Qt6. This project is still in (very) early deve

Dan 355 Jan 01, 2023
A keyboard-driven, vim-like browser based on PyQt5.

qutebrowser is a keyboard-focused browser with a minimal GUI. It’s based on Python and PyQt5 and free software, licensed under the GPL.

qutebrowser 8.4k Jan 01, 2023
Small Python scripts to take screenshot from a KaiOS/FFOS device and to mirror the screen of your phone.

This version of kaiscr is written by tkinter and can run in windows(use kailive-tk.py). "kailive-tk-speed.py" is speed optimization version. The sourc

openGiraffes Group 2 Mar 02, 2022
Rich.tui is a TUI (Text User Interface) framework for Python using Rich as a renderer.

rich.tui Rich.tui is a TUI (Text User Interface) framework for Python using Rich as a renderer. The end goal is to be able to rapidly create rich term

Will McGugan 17.1k Jan 04, 2023
A simple todo GUI applicaiton

simple_todo_gui A simple todo GUI applicaiton To create an .exe file, run 'Python setup.py build' after installing PyQt5 and cx_Freeze with pip. Then

Dhammike Piyumal 2 Nov 11, 2021
ROS2 + PyQt5 Example

ROS2 + PyQt5 Example

Ar-Ray 4 Nov 15, 2022
These are some useful tkinter utilities that i like to personally use.

ntkutils nefs tkinter utilities These are some useful tkinter utilities that i like to personally use. I upload this here because someone might wants

nef 7 Dec 06, 2022
🧮A simple calculator written in python allows you to make simple calculations, write charts, calculate the dates, and exchange currency.

Calculator 🖩 A simple calculator written in python allows you to make simple calculations, write charts, calculate the dates, and exchange currency.

Jan Kupczyk 1 Jan 15, 2022
Tukaan is the new framework that aims to replace Tkinter

Tukaan is the new, pythonic and colorful (like a keel-billed toucan) framework that aims to replace Tkinter. It has everything (on my computer, not at GitHub) that you need to develop cross-platform

Tukaan 101 Jan 08, 2023
A lightweight file-copying interface.

autosort A lightweight file-copying interface. Preview What is autosort? Autosort is a lightweight file-copying interface. It allows you to copy sever

32 Jan 02, 2023
Tkinter-ATM - Python GUI case made with Tkinter

tkinter-ATM Python GUI case made with Tkinter The task of this case was to creat

2 Jan 13, 2022
This is a GUI based text and image messenger. Other functionalities will be added soon.

Pigeon-Messenger (Requires Python and Kivy) Pigeon is a GUI based text and image messenger using Kivy and Python. Currently the layout is built. Funct

4 Jan 21, 2022
A GUI frontend developed in Python3 for simple admin tasks on MySQL-Server running on the localhost

A GUI frontend developed in Python3 for simple admin tasks on MySQL-Server running on the localhost. Developed for my CS School Project.

1 May 29, 2022
Learn to build a Python Desktop GUI app using pywebview, Python, JavaScript, HTML, & CSS.

Python Desktop App Learn how to make a desktop GUI application using Python, JavaScript, HTML, & CSS all thanks to pywebview. pywebview is essentially

Coding For Entrepreneurs 55 Jan 05, 2023
Cross-platform BrowserViews for the desktop.

Webview We use wxPython Phoenix to provide webviews. It's cross platform between Windows and macOS primarily, Linux versions require extra setup. Appl

1 Feb 12, 2022
Pyint is the graphic software which is written in Python

Pyint About Pyint Pyint is the graphic software which is written in Python(I use the Turtle graphics). The name 'Pyint' is compound word of 'Python' a

John 1 Nov 06, 2021
Uma interfáce de usuário relativamente simples em pyqt5 + escolha de dispositivos

Interface para Scrcpy Uma interfáce de usuário relativamente simples em pyqt5 para sistemas UNIX Requerimentos: Python3 PyQt5 adb scrcpy Você pode ins

hayukimori 10 Dec 16, 2022
Make nixos usable for non-technical users through a settings / package management GUI.

Nix-Gui Make nixos usable for non-technical users through a settings / package management GUI. Motives The declarative nature of ni

547 Dec 31, 2022
Turn (almost) any Python command line program into a full GUI application with one line

Gooey Turn (almost) any Python 2 or 3 Console Program into a GUI application with one line Support this project Table of Contents Gooey Table of conte

Chris 17k Jan 09, 2023