-
-
Save Olikonsti/879edbf69b801d8519bf25e804cec0aa to your computer and use it in GitHub Desktop.
import ctypes as ct | |
def dark_title_bar(window): | |
""" | |
MORE INFO: | |
https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute | |
""" | |
window.update() | |
DWMWA_USE_IMMERSIVE_DARK_MODE = 20 | |
set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute | |
get_parent = ct.windll.user32.GetParent | |
hwnd = get_parent(window.winfo_id()) | |
rendering_policy = DWMWA_USE_IMMERSIVE_DARK_MODE | |
value = 2 | |
value = ct.c_int(value) | |
set_window_attribute(hwnd, rendering_policy, ct.byref(value), ct.sizeof(value)) |
Olikonsti
commented
Jan 15, 2022
Nice
I'm on windows 10 and it's not working properly.….I mean when I
run my code….it doesn't show any changes...but when I minimize
my window and maximize it again..only then it shows me the
dark title bar
Is there any solution to that?
Well it sure is looking nice but well….not working properly 😅
I think it only works properly on windows 11. i did not find a solution for windows 10. but you could try to iconify() and deiconify() the window at startup
2022-03-26-201634.mp4
Maybe a stupid question but how can I set the title bar back to white? :)
@HuyHung1408 pass 0 as the value, that will do it.
def light_title_bar(window):
window.update()
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
get_parent = ct.windll.user32.GetParent
hwnd = get_parent(window.winfo_id())
rendering_policy = DWMWA_USE_IMMERSIVE_DARK_MODE
value = 0
value = ct.c_int(value)
set_window_attribute(hwnd, rendering_policy, ct.byref(value), ct.sizeof(value))
Thanks!
Just changing the window size worked on win10 for me.
#Changes the window size root.geometry(str(root.winfo_width()+1) + "x" + str(root.winfo_height()+1)) #Returns to original size root.geometry(str(root.winfo_width()-1) + "x" + str(root.winfo_height()-1))
worked for me, thanks dude!
This works properly .................................
import ctypes as ct
from tkinter import *
root = Tk()
root.update()
root.iconify()
DWWMA_USE_IMMERSIVE_DARK_MODE = 20
set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
get_parent = ct.windll.user32.GetParent
hwnd = get_parent(root.winfo_id())
renduring_policy = DWWMA_USE_IMMERSIVE_DARK_MODE
value = 1
value = ct.c_int(value)
set_window_attribute(hwnd, renduring_policy, ct.byref(value), ct.sizeof(value))
root.update_idletasks()
root.deiconify()
root.mainloop()
Didn't work on Windows 11, title bar is same color as before.
try it now...
import ctypes as ct from tkinter import *
root = Tk() root.update() root.iconify()
DWWMA_USE_IMMERSIVE_DARK_MODE = 20 set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute get_parent = ct.windll.user32.GetParent hwnd = get_parent(root.winfo_id()) renduring_policy = DWWMA_USE_IMMERSIVE_DARK_MODE value = 1 value = ct.c_int(value) set_window_attribute(hwnd, renduring_policy, ct.byref(value), ct.sizeof(value)) root.update_idletasks()
root.deiconify() root.mainloop()
Doesn't work.
try this one if it doesn't work then minimize the window and maximize it if u r getting any error then pls tell me...
import ctypes as ct
from tkinter import *
root = Tk()
root.update()
root.geometry("600x400")
root.config(bg="#222")
DARK_MODE = 20
set_windows_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
get_parent = ct.windll.user32.GetParent
hwnd = get_parent(root.winfo_id())
value = 2
value = ct.c_int(value)
renduring_policy = DARK_MODE
set_windows_attribute(hwnd, renduring_policy, ct.byref(value), ct.sizeof(value))
root.mainloop()
try this one if it doesn't work then minimize the window and maximize it if u r getting any error then pls tell me...
import ctypes as ct from tkinter import *
root = Tk() root.update() root.geometry("600x400") root.config(bg="#222")
DARK_MODE = 20 set_windows_attribute = ct.windll.dwmapi.DwmSetWindowAttribute get_parent = ct.windll.user32.GetParent hwnd = get_parent(root.winfo_id()) value = 2 value = ct.c_int(value) renduring_policy = DARK_MODE set_windows_attribute(hwnd, renduring_policy, ct.byref(value), ct.sizeof(value))
root.mainloop()
This worked, but how can I make it so its black all the time. Bypassing peoples custom accent color.
Yes write after the geometry add this root.iconify()
root.update()
Then at last before the root.mainloop add this
root.deconify()
Then it will work properly...
You can install the pywinstyles module for Windows 11 and go through it on pypy website and search this module "pywinstyles". You can customise the Windows very beautifully through it go to the project description thoroughly then u will understand after watching the pics...
thank you for sharing @SarthakTools https://github.com/Akascape/py-window-styles