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)
Software com funçoes de A a Z feito no Python

Introdução Iniciante em programação Python, decidi criar um programa com diversas ferramentas de A a Z. Funções Ferramenta de Gerenciamento e Manutenç

João Pedro 1 Jan 26, 2022
GUI based app made in python using tkinter

Virtual Keyboard A GUI application made in python using tkinter This is my first ever proper GUI based application project after learning tkinter rece

AbhineetK 10 Dec 10, 2022
Advanced GUI Calculator with Beautiful UI and Clear Code.

Advanced GUI Calculator with Beautiful UI and Clear Code.

Mohammad Dori 3 Jul 15, 2022
Key Cast - Cast your key presses and mouse clicks on the screen, while casting your favorite application on the screen. Better than the rest.

Key Cast Screen cast your keyboard and mouse clicks in style Project Homepage » View Demo · Report Bug · Request Feature Table of Contents Introductio

Mehul Singh Teya 13 Dec 23, 2022
This is a GUI application to plot functions in the form Y = F(X)

Plotter This is a GUI application to plot functions in the form Y = F(X) Technologies Python Qt designer Python unittest matplotlib Running Navigate

ahmedasad236 3 Dec 26, 2021
Create highly interactive web pages purely in Python

A package for building highly interactive user interfaces in pure Python inspired by ReactJS.

701 Jan 03, 2023
GUI to enable user selection of measurement and station in kHTConnector module.

kHTGui GUI to enable user selection of measurement and station in kHTConnector module. Helper tool for PowerBI users If you're planning to import data

kk 1 Jan 26, 2022
MediaPlayer-with-PyQt5 - The Multimedia Player with Python and PyQt5

MediaPlayer-with-PyQt5 I made this Multimedia Player with Python and PyQt5, I re

4 Oct 06, 2022
Mini is a web browser application based on the Python PyQt web engine, made in 290 lines of code.

Mini Mini is a web browser application based on the Python PyQt web engine, made in 290 lines of code. The code is written and published as is, so the

Dmitry Karpenko 6 Nov 07, 2022
PyCG: Practical Python Call Graphs

PyCG - Practical Python Call Graphs PyCG generates call graphs for Python code using static analysis. It efficiently supports Higher order functions T

Vitalis Salis 185 Dec 29, 2022
A Python based Connect 4 game made with DearPyGUI

Ultimate-Connect-4 A Python based Connect 4 game made with DearPyGUI NOTICE: If you connect to the game server hosted by Jah-On and attempt to send ma

4 Jun 01, 2022
Signin/Signup GUI form using tkinter in python

SignIn-SignUpFormRepo Hello there, I am Shahid and this is the Signin/Signup GUI form using tkinter in python if you want to use avatar images then pa

Shahid Akhtar 1 Nov 09, 2021
ZFS Administration GUI

ZYGGY ZFS Administration GUI Zyggy is a very simple GUI for basic ZFS administration. The system provides graphical access for most frequently used ZF

51 Dec 18, 2022
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 08, 2022
QGUI - 0.1MB超轻量Python GUI框架,用模板来快捷制作深度学习模型推理界面

QGUI - 0.1MB超轻量Python GUI框架,用模板来快捷制作深度学习模型推理界面

QPT Family 92 Nov 18, 2022
A simple fusee-launcher frontend for macOS

A simple fusee-launcher frontend for macOS (Universal). Supports macOS = 10.9. It has libusb statically linked, so you don't need to install anything

rob 25 Dec 19, 2022
GUIOfTemperatureConverterUsingPython - GUI Of Temperature Converter Using Python

Fahrenheit To Celcius GUI Of Temperature Converter Below Video is the Output Of

SUJITHA RASAMSETTY 0 Mar 06, 2022
A Simple GUI application to organize and store accounts/passwords.

PyssView A Simple GUI application to organize and store accounts/passwords. Install/Run (Linux) Via script This way will install a binary version and

Jefferson Richard Dias 1 Nov 24, 2021
TkArt - A repository created to explore geometry and art creation using TkInter

tkArt A repository created to explore geometry and art creation using TkInter, a

Jayant Sogikar 18 Oct 01, 2022
Generate multifunctional GUIs from classes

magic-class In magicgui you can make simple GUIs from functions. However, we usually have to create GUIs that are composed of several buttons, and eac

25 Dec 15, 2022