Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to remove the title bar in a Tkinter window without using overrideredirect() method?
To remove the title bar of a Tkinter window, we can use wm_attributes() method by specifying the type of property. In the following example, we will use '-fullscreen', a Boolean value that removes the title bar of the window.
Example
Here's how to create a fullscreen window without a title bar ?
# Import the tkinter library
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
win.geometry("700x350")
# Create a Label to print the Name
label = Label(win, text="This is a New Line Text", font=('Helvetica', 14, 'bold'), foreground="red3")
label.pack()
# Remove title bar by setting fullscreen mode
win.wm_attributes('-fullscreen', 'True')
win.mainloop()
Alternative Methods
Method 1: Using -type attribute (Linux)
On Linux systems, you can use the -type attribute ?
import tkinter as tk
root = tk.Tk()
root.wm_attributes('-type', 'splash')
root.geometry("400x300")
label = tk.Label(root, text="Window without title bar", font=('Arial', 12))
label.pack(expand=True)
root.mainloop()
Method 2: Using -toolwindow attribute (Windows)
On Windows, you can use the -toolwindow attribute ?
import tkinter as tk
root = tk.Tk()
root.wm_attributes('-toolwindow', True)
root.geometry("400x300")
label = tk.Label(root, text="Tool window without title bar", font=('Arial', 12))
label.pack(expand=True)
root.mainloop()
Adding Exit Functionality
Since removing the title bar also removes the close button, add an exit method ?
from tkinter import *
def close_window():
win.destroy()
win = Tk()
win.geometry("400x300")
# Remove title bar
win.wm_attributes('-fullscreen', True)
# Add content
label = Label(win, text="Press Escape or click Close to exit", font=('Arial', 14))
label.pack(pady=50)
close_btn = Button(win, text="Close", command=close_window, font=('Arial', 12))
close_btn.pack()
# Bind Escape key to close window
win.bind('<Escape>', lambda e: close_window())
win.mainloop()
Comparison
| Method | Platform | Effect |
|---|---|---|
-fullscreen |
All | Fullscreen without title bar |
-type splash |
Linux | Borderless window |
-toolwindow |
Windows | Tool window without title bar |
Conclusion
Use wm_attributes('-fullscreen', True) for cross-platform title bar removal. Remember to provide alternative exit methods when removing the title bar, as users lose access to the standard close button.
Advertisements
