How to make a window fixed in size in Tkinter?

Tkinter is the Python GUI library that has the tools required for building user interfaces.  Sometimes, you may need to create a window with a fixed size that the user cannot resize or maximize. Windows with fixed sizes help maintain a consistent layout and and makes sure your app looks exactly the way you want it to be. In this blog, we will learn how to fix size of a window in Tkinter.

Step 1 : Create a basic window in Tkinter.

Now, let’s see how to make an elementary window in Tkinter. We set the default dimensions of the window to 450×250 pixels using the inbuilt geometry() function.

import tkinter as tk 

# Create the main window
root = tk.Tk() 
root.title("Fixed Size Window Example")

# Set the window size
root.geometry("450x250") 

# Add a label
label1 = tk.label(root, text = "This window has default size of 650x350 pixels")
label1.grid(row = 0, column = 0)

# run the application
root.mainloop()
Output: Resizable window in Tkinter

This program creates a very simple window with a title and of size 450×250 pixels. By default the user can resize this window by dragging its edges.

Step 2 : Making the window fixed sized.

Although we have set the window size to 450×250, the user is able to resize it. To avoid this we simply disable resizable() function on the root window as shown below:

root.resizable(False,False)

This allows us to disable resizing of window as demonstrated by an example:

import tkinter as tk

# Create the main window
root = tk.Tk()
root.title("Fixed Size Window Example") 

# Set the window size and disable resizing
root.geometry("450x250")
root.resizable(False,False)

# Add a label
label1 = tk.Label(root, text="This window has a default size of 650x350 pixels.")
label1.grid(row='0',column='0')

# Run the application
root.mainloop()
Output:
Fixed size window in Tkinter

This program will create a small window 450×250 pixels that cannot be resized. The window maximize option has also been disabled.

Conclusion:

Making a fixed-size window in Tkinter isn’t difficult at all. The resizable function sets the resize options for windows. This will come in handy when making professional and organized GUIs—particularly interfaces such as forms or data entry applications where layout should not change.

Leave a Comment

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

Scroll to Top