How to center a window on the screen in Tkinter?

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center.

We can also set the window to its center programmatically by defining its geometry.


#Import the tkinter library
from tkinter import *

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

#Set the geometry

win.eval('tk::PlaceWindow . center')



Running the above code will create a centered window.

Updated on: 26-Mar-2021

17K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started