marticliment / win32mica

Win32mica: a simple module to add the Mica effect on legacy python windows.
https://pypi.org/project/win32mica
MIT License
95 stars 5 forks source link

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

Closed HuyHung1408 closed 2 years ago

HuyHung1408 commented 2 years ago

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

marticliment commented 2 years ago

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

marticliment commented 2 years ago

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 :')

HuyHung1408 commented 2 years ago

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!

marticliment commented 2 years ago

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.

HuyHung1408 commented 2 years ago

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!

marticliment commented 2 years ago

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

Could you please try version 1.6?

HuyHung1408 commented 2 years ago

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