Python | geometry method in Tkinter
Tkinter is a Python module which is used to develop GUI (Graphical User Interface). It comes along with the Python so one do not has to install but can be done using pip command.
Tkinter provides various universal method one of them is geometry() method. This method is used to set the dimensions of the Tkinter window as well as it is used to set the position of the main window on the user’s desktop.
Code #1: Tkinter window without using geometry method.
# importing only those functions which are needed from tkinter import Tk, mainloop, TOP from tkinter.ttk import Button # creating tkinter window root = Tk() button = Button(root, text = 'Geeks') button.pack(side = TOP, pady = 5) mainloop() |
Output:

As soon as you run the application you’ll see the position of the Tkinter window is at the north-west position of the screen and size of the window is also small as shown in output.
Code #2:
# importing only those functions which # are needed from tkinter import Tk, mainloop, TOP from tkinter.ttk import Button # creating tkinter window root = Tk() # creating fixed geometry of the # tkinter window with dimensions 150x200 root.geometry('200x150') button = Button(root, text = 'Geeks') button.pack(side = TOP, pady = 5) mainloop() |
Output:

After running the application you’ll see that the size of the Tkinter window is changed but the position on the screen is same.
Code #3:
# importing only those functions which # are needed from tkinter import Tk, mainloop, TOP from tkinter.ttk import Button # creating tkinter window root = Tk() # creating fixed geometry of the # tkinter window with dimensions 150x200 root.geometry('200x150 + 400 + 300') button = Button(root, text = 'Geeks') button.pack(side = TOP, pady = 5) mainloop() |
Output:

When you run the application you’ll observe that the position and size both are changed. Now the Tkinter window is appearing on different position (300 shifted on Y-axis and 400 shifted on X-axis).
Note: We can also pass variable argument in the geometry method but it should be in the form (variable1) x (variable2) otherwise it will raise an error.
Recommended Posts:
- Python | after method in Tkinter
- maxsize() method in Tkinter | Python
- Python | place() method in Tkinter
- minsize() method in Tkinter | Python
- iconphoto() method in Tkinter | Python
- resizable() method in Tkinter | Python
- Python | pack() method in Tkinter
- Python | grid() method in Tkinter
- destroy() method in Tkinter | Python
- Python Tkinter | grid_location() and grid_size() method
- Python | forget_pack() and forget_grid() method in Tkinter
- Python Tkinter | Moving objects using Canvas.move() method
- Python GUI - tkinter
- RadioButton in Tkinter | Python
- Different messages in Tkinter | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



