pythonwindowstkintercustomizationtitlebar

Python Tkinter Change Colour of Tile Bar


Most applications have a customised title bar, take VSC for example: Vsc title bar See all the button and custom colour. All I want to do is change the colour to any colour, not just black like in this post (second answer). I am using windows 11, python 3.12.9.

I haven't tried anything yet because I have no idea where to start from! If it helps, I am building it using pyinstaller and mabye I could change it after it has been built?

Thanks in advance!


Solution

  • You can use the pywinstyles module for doing that.

    First, install it with the following command:

    pip install pywinstyles
    

    Then, you can change the color of the title bar using the change_header_color() function from pywinstyles like this:

    import tkinter as tk, pywinstyles
    
    window = tk.Tk()
    
    # Change the title bar color
    pywinstyles.change_header_color(window, "#987654")
    
    window.mainloop()
    

    Here's the result:

    tkinter window with custom title bar color

    Please note that this will only work on Windows 11. If you want to change the title bar color on other Windows versions, you should consider creating your own title bar and hiding the one provided by the system.