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 can I prevent a window from being resized with Tkinter?
Tkinter windows can be resized automatically by hovering and pulling over the window borders. We can disable the resizable property using the resizable(boolean value) method. We will pass False value to this method which will disable the window from being resized.
Example
Here's how to create a non-resizable Tkinter window ?
# Import the tkinter library
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
# Set the geometry
win.geometry("650x250")
Label(win, text="Hello World", font=('Times New Roman bold', 20)).pack(pady=20)
# Make the window non-resizable
win.resizable(False, False)
win.mainloop()
Alternative Methods
Using maxsize() and minsize()
You can also fix the window size by setting both maximum and minimum size to the same values ?
from tkinter import *
win = Tk()
win.geometry("400x300")
# Set both min and max size to same values
win.minsize(400, 300)
win.maxsize(400, 300)
Label(win, text="Fixed Size Window", font=('Arial', 16)).pack(pady=50)
win.mainloop()
Disabling Only Horizontal or Vertical Resize
You can disable resizing in only one direction by passing different boolean values ?
from tkinter import *
win = Tk()
win.geometry("500x300")
# Disable horizontal resize only (width fixed, height resizable)
win.resizable(False, True)
Label(win, text="Height Resizable Only", font=('Arial', 14)).pack(pady=100)
win.mainloop()
Comparison
| Method | Syntax | Best For |
|---|---|---|
resizable(False, False) |
Simple boolean values | Complete resize prevention |
minsize() + maxsize() |
Specific pixel values | More control over bounds |
resizable(False, True) |
Mixed boolean values | Partial resize control |
Output
Running any of the above code examples will display a Tkinter window that cannot be resized (or resized only in allowed directions). The window will maintain its fixed dimensions regardless of user interaction with the borders.
Conclusion
Use resizable(False, False) to completely prevent window resizing. For more granular control, use minsize() and maxsize() methods or enable resizing in only one direction.
