In Python, the Tkinter library has an amazing feature which is the geometry method. The geometry( ) helps to set a new window size dynamically.
It is very simple. We just need to follow a few steps.
- At first we need to import the Tkinter library. It contains the geometry method.
- After that create a variable where we can store the window.
- Then we can initialize the of the window like x = 500 and y = 500. I choose both windows the same size just to look nice the showing window.
- Then I just use the geometry method for setting the window size.
- In this method we just use the f-string method to do this. If you want then you can use another way like .format method. It is also considerable.
- So, in the f string method, both variables store their own value.
*NOTE: What is f-string?
Python 3.6 is introduce F-string. Basically F-string are string literals that have an f before the opening quotetion mark. It is the printing method . It is very much user friendly by using add variables, comma separators.It also enhance code readibility and maintainability.
String format( ) is also a method that we can use.
import tkinter as size setWindow=size.Tk() x=500 y=500 setWindow.geometry(f"{x}x{y}") setWindow.mainloop()
The size of x and y is decided how was the window look like. The length is 500 and width is also 500 thats why windows every sides are same type. This also looks good. But if you want, you can change the length and width according to your choice.
Output: