Python Tkinter Program To Center The Window Position

01. Example:

import tkinter as tk

root = tk.Tk()
root.title('Tkinter Title')

windowWidth = 640
windowHeight = 480

screenWidth = root.winfo_screenwidth()
screenHeight = root.winfo_screenheight()

xCenter = int(screenWidth/2 - windowWidth / 2)
yCenter = int(screenHeight/2 - windowHeight / 2)

root.geometry(f'{windowWidth}x{windowHeight}+{xCenter}+{yCenter}')

root.mainloop()

Output: Window in center position.

Window-Center-Position

Leave a comment