- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
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()
Running the above code will make the window constant to its size which is nonresizable.
- 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 add a margin to a tkinter window?
- How to resize the background image to window size in Tkinter?
- How to make a Tkinter window not resizable?
- How to delete Tkinter widgets from a window?
- How to set the position of a Tkinter window without setting the dimensions?
- How to set the font size of a Tkinter Canvas text item?
- How do I close a tkinter window?
- How to close a Tkinter window by pressing a Button?
- How to create a child window and communicate with parents in Tkinter?
- How to set padding of all widgets inside a window or frame in Tkinter?
- How to specify where a Tkinter window should open?
- How can I prevent a window from being resized with Tkinter?