Geometry Method in Python Tkinter (original) (raw)

Last Updated : 28 Apr, 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.

[GFGTABS]
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()

`

``
[/GFGTABS]

**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.

[GFGTABS]
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()

`

``
[/GFGTABS]

**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.

[GFGTABS]
Python

``

`from tkinter import Tk from tkinter.ttk import Button

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

`

``
[/GFGTABS]

**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: