
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Set a Tkinter Window with a Constant Size?
Sometimes, the tkinter frame gets resized automatically according to the size of the widgets. To make the frame constant in size, we have to stop the widgets to resize the frame. So there are three methods,
Boolean pack_propagate(True/False) method prevents the resizing of the frame from the widget.
resizable(x,y) method prevents the window to be resized.
Pack(fill, expand) values which resize the window to its defined size in the geometry.
Basically, all the widgets inside the tkinter frame will be responsive and cannot be resized.
Example
from tkinter import * win= Tk() win.geometry("700x300") #Don't allow the screen to be resized win.resizable(0,0) label= Label(win, text= "Select an option", font=('Times New Roman',12)) label.pack_propagate(0) label.pack(fill= "both",expand=1) def quit(): win.destroy() #Create two buttons b1= Button(win, text= "Continue") b1.pack_propagate(0) b1.pack(fill="both", expand=1) b2= Button(win, command= quit, text= "Quit") b2.pack_propagate(0) b2.pack(fill="both", expand=1) win.mainloop()
Output
Running the above code will make the window constant to its size which is nonresizable.
- Related Articles
- How to set a Tkinter window to a constant size?
- How do I set a minimum window size in Tkinter?
- How to set a widget's size in Tkinter?
- How to resize the background image to window size in Tkinter?
- How to set the position of a Tkinter window without setting the dimensions?
- How to add a margin to a tkinter window?
- How to set the font size of a Tkinter Canvas text item?
- How to set padding of all widgets inside a window or frame in Tkinter?
- How to make a Tkinter window not resizable?
- How to delete Tkinter widgets from a window?
- How to create a child window and communicate with parents in Tkinter?
- How to close a Tkinter window by pressing a Button?
- How do I close a tkinter window?
- How to set the size of the browser window in Selenium?
- How can I prevent a window from being resized with Tkinter?

Advertisements