Python: Tkinter: How to change the windows border color?

Question:

Every result I’ve gotten from searching this question up has to do with changing the border color for Tkinter widget’s WITHIN the main app window, or changing the background color and stuff.

What I’m looking to do is actually change the windows border color itself. Which I have marked in this picture here
enter image description here

I read some stuff concerning ‘Styles’ but it didn’t seem to be what I was looking for.
Can anyone help point me to a tutorial for changing this, or explain how it can be done?

Or if there is a question that asked exactly the same question I was asking that is answered point me to it.

Asked By: Micrified

||

Answers:

As I see you are using windows.

This color is set by the theme you are currently using. It is the same for every window.

So I cross out the possibility of only using the Tkinter module for this.

Tkinter is responsible for what is in the window but the window manager decides about the border. For example in Ubuntu the window would look totally different.

I guess, you would need some windows specific calls for that.

You can remove the border with root.overrideredirect(1) if I remember correctly.

PS: put “windows” into the tags of this question.

Answered By: User

Hi I was looking for this answer too, found it after like 80 minutes searching, Only work, to activate DWMWA_USE_IMMERSIVE_DARK_MODE
found it here: Can I change the title bar in Tkinter?

I didnt found dwmwindowattribute in dwmwindowattribute that affect Top bar color sadly :(.

For border colour:

It should be possible to call DWMWA_BORDER_COLOR, but honestly I dont know how, there is some article calling it in C++ here:
change-the-color-of-the-title-bar-caption-of-a-win32-application

Tried this but doesnt work:
set_window_attribute(hwnd, 22, '0x000000FF', 4)

Here is working code for pure black top:

import tkinter as tk
import ctypes as ct


def dark_title_bar(window):
    """
    MORE INFO:
    https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    """
    window.update()
    set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
    get_parent = ct.windll.user32.GetParent
    hwnd = get_parent(window.winfo_id())
    value = 2
    value = ct.c_int(value)
    set_window_attribute(hwnd, 20, ct.byref(value),
                         4)

root = tk.Tk()
root.title("Crystaly Ball")
root.geometry("1400x900")
root.configure(background="#222246")
dark_title_bar(root)
root.mainloop()
Answered By: Jakub