marticliment / win32mica

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

Home Page:https://pypi.org/project/win32mica

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

HuyHung1408 opened this issue · comments

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:

2022-03-07-144115.mp4

Uh, weird... Can you please send me the code of the sample app you made so I can test it?

Uh, weird... Can you please send me the code of the sample app you made so I can test it?

Only if you want to, no reqiurement. It's because my ssd died and i lost my test app :')

It is just a small program to test how it works.

import tkinter as tk
from tkinter import Label, ttk
from win32mica import MICAMODE, ApplyMica
from ctypes import windll

app=tk.Tk()
app.geometry('200x200')
app.title('Test')

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()

a = Label(text='App theme:', font=('Segoe UI Variable Display', '14')).grid(row=1, column=1, padx=4)

# Switch
Lb = ttk.Radiobutton(app, text='Light', command=Light, value =1).grid(row =3, column= 1, pady=3)
Db = ttk.Radiobutton(app, text='Dark', command=Dark, value=2).grid(row= 4, column=1, pady=3)

app.tk.call("source", "sun-valley.tcl")
app.tk.call("set_theme", "light")

app.mainloop()

https://github.com/rdbende/Sun-Valley-ttk-theme needs this to work!

Hi!, i've been testing the module, and as far as I can see, this seems to be a Windows bug. Just have in mind that win32mica uses hidden APIs to enable a behaviour that shouldn't exist. I reckon microsoft will get this fix in one of those dev builds where the mica API is public.

Hi!, i've been testing the module, and as far as I can see, this seems to be a Windows bug. Just have in mind that win32mica uses hidden APIs to enable a behaviour that shouldn't exist. I reckon microsoft will get this fix in one of those dev builds where the mica API is public.

Thank you!

Hi @HuyHung1408, i've found a workaround that (in theory) works.

Could you please try version 1.6?

I'm not in Windows 11 right now, compatibility issue. I will try as soon as possible!