How do I set a minimum window size in Tkinter?

In Tkinter, windows are resizable by default, but you can set a minimum window size to prevent users from making the window too small. This ensures your GUI elements remain visible and usable.

Setting Minimum Window Size

Use the minsize() method to set the minimum width and height of a Tkinter window. The syntax is minsize(width, height) where both parameters are in pixels.

Example

Here's how to create a window with a minimum size of 400x300 pixels ?

# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame
win = Tk()
win.title("Minimum Window Size Demo")

# Set minimum window size to 400x300 pixels
win.minsize(400, 300)

# Create a text label
Label(win, text="This window has a minimum size of 400x300", 
      font=('Helvetica', 14)).pack(pady=50)

Label(win, text="Try to resize the window - it won't go smaller!", 
      font=('Helvetica', 12)).pack(pady=10)

win.mainloop()

Setting Both Minimum and Maximum Size

You can combine minsize() with maxsize() to create a window with size constraints ?

from tkinter import *

win = Tk()
win.title("Size Constrained Window")

# Set minimum size (300x200) and maximum size (800x600)
win.minsize(300, 200)
win.maxsize(800, 600)

# Add some content
Label(win, text="Window size is constrained", 
      font=('Arial', 16)).pack(pady=20)
Label(win, text="Min: 300x200, Max: 800x600", 
      font=('Arial', 12)).pack(pady=10)

win.mainloop()

Practical Use Cases

Setting minimum window size is useful when ?

  • Your GUI has multiple widgets that need minimum space
  • Text or images might become unreadable if the window is too small
  • You want to maintain a professional appearance

Key Points

Method Purpose Parameters
minsize() Set minimum window size width, height (in pixels)
maxsize() Set maximum window size width, height (in pixels)
resizable() Control window resizing width_bool, height_bool

Conclusion

Use minsize(width, height) to prevent users from making your Tkinter window too small. This ensures your GUI remains functional and visually appealing across different screen sizes.

Updated on: 2026-03-25T18:27:24+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements