How to center a window on the screen in Tkinter?

In Tkinter, centering a window on the screen can be achieved using multiple approaches. The most common methods are using the tk::PlaceWindow command or calculating the center position manually with geometry settings.

Using tk::PlaceWindow Command

The simplest method is using Tkinter's built-in tk::PlaceWindow command ?

# Import the tkinter library
from tkinter import *

# Create an instance of tkinter frame
win = Tk()

# Set the window title and geometry
win.title("Centered Window")
win.geometry("600x250")

# Center the window using tk::PlaceWindow
win.eval('tk::PlaceWindow . center')

win.mainloop()

Manual Centering with Geometry Calculation

You can also center the window by calculating the screen dimensions and positioning it manually ?

from tkinter import *

# Create an instance of tkinter frame
win = Tk()
win.title("Manually Centered Window")

# Define window dimensions
window_width = 600
window_height = 250

# Get screen dimensions
screen_width = win.winfo_screenwidth()
screen_height = win.winfo_screenheight()

# Calculate center position
center_x = int(screen_width / 2 - window_width / 2)
center_y = int(screen_height / 2 - window_height / 2)

# Set geometry with calculated position
win.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')

win.mainloop()

Comparison

Method Code Length Cross-Platform Best For
tk::PlaceWindow Short Yes Quick centering
Manual calculation Longer Yes Custom positioning control

Output

Both methods will create a window centered on the screen. The window appears at the center regardless of screen resolution.

Centered Tkinter Window

Conclusion

Use tk::PlaceWindow . center for quick window centering. For more control over positioning, calculate the center coordinates manually using screen dimensions.

Updated on: 2026-03-25T18:26:45+05:30

22K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements