marticliment / win32mica

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

How to disable 'ApplyMica' after use - Or - How to disable 'ApplyMica' for a specific widget in 'customtkinter'? #21

Closed Nigacatch closed 1 month ago

Nigacatch commented 2 months ago

Hello @marticliment, thank you very much for making this library because it has a great impact on the appearance of the program! I use the following code to apply Mica style:

class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()
        self.title("Talayar")
        self.geometry(center(self, 720, 1280))
        self.resizable(False, False)
        customtkinter.set_appearance_mode('dark')
        mode = MicaTheme.DARK 
        style = MicaStyle.ALT 
        hwnd = self.frame()  
        ApplyMica(HWND=hwnd, Theme=mode, Style=style)

This code is applied globally to the entire program and all widgets. Now my problem is that I want to put several photos in the program, but the color of the photo gets mixed up... For example, look at the photo below, both photos are the same, but the colors are different:

pic

Now the question is, how can I fix this problem and 'ApplyMica' does not affect the photos?

marticliment commented 2 months ago

Are your photos semi-transparent?

I suggest drawing an opaque rectangle/background under your photos

Nigacatch commented 2 months ago

@marticliment, Thank you for your reply! No, the photos are not semi-transparent. You can see the original photo in the below:

Screenshot 2024-07-30 195245

I drew two black and white rectangles under the photo, but it didn't change:

Screenshot 2024-07-30 200547

Screenshot 2024-07-30 200618

What should I do? thank you.

marticliment commented 2 months ago

It is interesting that the black rectangle is also showing tinted...

I have never seen this issue, could it be caused by customtkinter? Please try to draw the same picture on plain tkinter, with win32mica

Nigacatch commented 2 months ago

@marticliment, The problem still persists...

Screenshot 2024-07-30 221728

Screenshot 2024-07-30 2221

it's very interesting!

marticliment commented 2 months ago

Try to do something: Tk draws transparency by specifying the "transparency" color, and then rendering it transparent on the window. Any text, image or element that contains that color will have that color rendered transparent.

See the following code: image

Try to add the app.configure and the app.wm_attributes, but set a random color to the color, instead of black

Nigacatch commented 2 months ago

@marticliment, The above code is considered an improvement, but unfortunately, the style of the program is messed up...

By applying the code above:

Screenshot 2024-07-31 160028

Without applying the code above:

Screenshot 2024-07-31 155953

marticliment commented 2 months ago

Try to set the transparent background to #16191e, which is the background color used by your Tkinter flavour

Nigacatch commented 2 months ago

@marticliment, 'ApplyMica' is applied to the background but not to the widgets...

After:

Screenshot 2024-07-31 223007

Before:

Screenshot 2024-07-31 160028

marticliment commented 2 months ago

I am afraid I then don't know what is happening. looks like customtkinter is using a different method to render transparencies, and that it is affecting your image, and virtually any control.

I am afraid I can't help you with that, since I don't know how customtkinter works here.

Nigacatch commented 2 months ago

@marticliment, You have helped a lot so far and I am grateful to you! I will message the owner of 'customtkinter' and ask him to look at this issue and explain if he can.

Nigacatch commented 1 month ago

@marticliment... With the help of @Akascape, the problem is finally solved and that's great.