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
How to create a resizable Windows without title bar in Tkinter?
To create a tkinter window without title bar, we can use overrideredirect(boolean) property which disables the navigation panel from the top of the tkinter window. However, it doesn't allow the user to resize the window instantly.
If we are required to create a resizable window without the title bar programmatically, then we can use Sizegrip(parent) widget in Tkinter. The Sizegrip widget adds extendibility to the application that allows users to pull and resize the main window. To work with Sizegrip widget, we have to bind the mouse buttons and a function that resizes the window whenever we pull the grip.
Example
Here's how to create a resizable window without title bar ?
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the window
win.geometry("700x350")
# Remove the Title bar of the window
win.overrideredirect(True)
# Define a function for resizing the window
def moveMouseButton(e):
x1 = win.winfo_pointerx()
y1 = win.winfo_pointery()
x0 = win.winfo_rootx()
y0 = win.winfo_rooty()
win.geometry("%sx%s" % ((x1-x0),(y1-y0)))
# Add a Label widget
label = Label(win, text="Grab the lower-right corner to resize the window")
label.pack(side="top", fill="both", expand=True)
# Add the gripper for resizing the window
grip = ttk.Sizegrip(win)
grip.place(relx=1.0, rely=1.0, anchor="se")
grip.lift(label)
grip.bind("<B1-Motion>", moveMouseButton)
win.mainloop()
How It Works
The code works by combining several key components ?
- overrideredirect(True) − Removes the title bar and window decorations
- ttk.Sizegrip() − Creates a small grip widget in the corner
- place(relx=1.0, rely=1.0, anchor="se") − Positions the grip at bottom-right
- <B1-Motion> event − Detects mouse dragging on the grip
- winfo_pointer methods − Get current mouse and window positions for resizing
Key Points
- The window will have no title bar, close button, or minimize/maximize buttons
- Users can only resize by dragging the grip widget in the bottom-right corner
- To close the window, you'll need to add your own close button or use Ctrl+C in terminal
- The grip widget automatically appears as a small diagonal lines icon
Conclusion
Using overrideredirect(True) with ttk.Sizegrip() creates a title bar-free window that remains resizable. The grip widget provides an intuitive way for users to resize the window by dragging from the corner.
