How to center a window on the screen in Tkinter?

TkinterPythonServer Side ProgrammingProgramming

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.

raja
Published on 26-Mar-2021 11:17:55
Advertisements