A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-geometry-method-in-tkinter/ below:

Geometry Method in Python Tkinter

Geometry Method in Python Tkinter

Last Updated : 11 Jul, 2025

Tkinter is a built-in Python module used for building desktop GUI applications. It's simple, powerful, and doesn’t require any external installation. Tkinter provides many methods, one of them is the geometry() method and it is used to control the size and position of the GUI window.

The geometry() method sets:

Examples of Geometry Method in Python Tkinter Example 1: Set Window Size with geometry()

Use geometry() to fix the window’s width and height.

Python
from tkinter import Tk
from tkinter.ttk import Button

w = Tk()
w.geometry('200x150')
btn = Button(w, text='Geeks')
btn.pack(pady=5)
w.mainloop()

Output: 

After running the application, you'll see that the size of the Tkinter window has changed, but the position on the screen is the same. 

geometry method to set window dimensions

Explanation:

Example 2: Set Size and Position Together

We can also set both size and on-screen position using offsets.

Python
from tkinter import Tk
from tkinter.ttk import Button

w = Tk()
w.geometry('200x150+400+300')
btn = Button(w, text='Geeks')
btn.pack(pady=5)
w.mainloop()

Output: 

When you run the application, you'll observe that the position and size both are changed. Now the Tkinter window is appearing at a different position (400 shifted on X-axis and 300 shifted on Y-axis).

geometry method to set the dimensions and position of the Tkinter window

Explanation:

Tkinter Window Without Using geometry() 

By default, the window appears in the top-left (northwest) corner with an automatic size.

Python
from tkinter import Tk
from tkinter.ttk import Button

w = Tk()
btn = Button(w, text='Geeks')
btn.pack(pady=5)
w.mainloop()

Output: 

As soon as we run the application, we'll see the position of the Tkinter window is at the northwest position of the screen and the size of the window is also small as shown in the output below. 

Tkinter window without geometry method

Explanation:

Note: We can also pass a variable argument in the geometry method, but it should be in the form (variable1) x (variable2); otherwise, it will raise an error.

Related articles:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4