In this video I’ll show you a quick hack to customize your Titlebar in Tkinter with Python.
Tkinter doesn’t come with the ability to customize your titlebar built into it. We’ll have to get creative and hack around a bit to create a custom title bar.
We’ll create a titlebar that we can change the color. We’ll also add the ability to drag and drop the app to move it around the screen by clicking and dragging and dropping the titlebar.
Python Code: title.py
(Github Code)
from tkinter import * root = Tk() root.title('Codemy.com - Change Titlebar Color') root.iconbitmap('c:/gui/codemy.ico') root.geometry("500x300") # remove title bar root.overrideredirect(True) def move_app(e): root.geometry(f'+{e.x_root}+{e.y_root}') def quitter(e): root.quit() #root.destroy() # Create Fake Title Bar title_bar = Frame(root, bg="darkgreen", relief="raised", bd=0) title_bar.pack(expand=1, fill=X) # Bind the titlebar title_bar.bind("", move_app) # Create Icon Here # Create title text title_label = Label(title_bar, text=" My Awesome App!!", bg="darkgreen", fg="white") title_label.pack(side=LEFT, pady=4) # Create close button on titlebar close_label = Label(title_bar, text=" X ", bg="darkgreen", fg="white", relief="sunken", bd=0) close_label.pack(side=RIGHT, pady=4) close_label.bind(" ", quitter) my_button = Button(root, text="CLOSE!", font=("Helvetica, 32"), command=root.quit) my_button.pack(pady=100) root.mainloop()
Hello from italy!
This way the app cannot be minimized, can it?
I tried because i wanted to test myself in creating different gui but cannot be able to minimize it (and this may be a big trouble creating an app.
Do you know any solutions?
Thanks for everything you do
You have to setup the minimize button and functionality. Just as John demonstrated, do the same only with a minimize button and function. Take a look at https://stackoverflow.com/questions/4481880/minimizing-a-tk-window for the programmatic solution.