HowTo: Tkinter hide title bar of windows

It took me quite some time to find the solution to make the title bar of a tkinter window disappear without forcing the window to become full screen or without destroying all bindings / functionality like buttons or event handlers.

Before/after

Left is the standard view which includes the OS specific header bar. On the right you can see the result, after hiding the header bar.

Code

# remove title bar... nice little tweak :)
root.overrideredirect(True)
root.overrideredirect(False)

Example

Full working example with a blank tkinter window.

import tkinter as tk

# create tk window
root = tk.Tk()
root.title('GCode File Explorer')

# remove title bar... nice little tweak :)
root.overrideredirect(True)
root.overrideredirect(False)

w = 690 # Width 
h = 600 # Height
 
screen_width = root.winfo_screenwidth()  # Width of the screen
screen_height = root.winfo_screenheight() # Height of the screen
 
# Calculate Starting X and Y coordinates for Window
x = (screen_width/2) - (w/2)
y = (screen_height/2) - (h/2)
 
root.geometry('%dx%d+%d+%d' % (w, h, x, y))  # center on screen


root.mainloop()

Schreibe einen Kommentar 0

Your email address will not be published. Required fields are marked *