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.

Example

#Import the tkinter library
from tkinter import *

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

#Set the geometry
win.geometry("600x250")

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

win.mainloop()

Output

Running the above code will create a centered window.

Updated on: 26-Mar-2021

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements