Set a constant window size using Tkinter.

In this tutorial, I will show you how to Set a constant window size using Tkinter in Python.

At first, I just had to import the Tkinter in my program pass. I am going to use the Tkinter name. I have written tri instead of Tkinter. It will save me time.

import tkinter as tri

Then I’ll have to create a variable. I am giving it netWindow. This is the variable where I’ll be storing my window. we can write this netWindow= tri. Tk(). I have created my first Window.

import tkinter as tri
netWindow= tri. Tk()

So I can using geometry we can set the window size. We are taking here 200 300.  You have to careful that for geometry method, we have to pass the size as a string writing the width X and height. We can write netWindow.geometry(“200×300”).

import tkinter as tri
netWindow= tri. Tk()
netWindow.geometry("200x300")

We can do this using this netWindow.resizable. You can see the name of this method and take idea what it does. By one that we cannot drag it to make it more smaller. Suppose we are taking 0,0.

But if run this program, nothing will happen. Because in Tkinter l have to run it in a main loop. I have to write this netWindow.mainloop().

import tkinter as tri
netWindow= tri. Tk()
netWindow.geometry("200x300")
netWindow.resizable(0,0)
netWindow.mainloop()

So, if I run it, we can see the specific sized window has appeared. But cannot drag it to increase and decrease the size of our Tkinter window.

Output:

 

Leave a Comment

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

Scroll to Top