0

i want set python window center position when the form is loaded how set.what i tried so far i attached below

from tkinter import *
from tkinter import messagebox
from subprocess import call

root = Tk()
root.title("Main")
root.geometry("500x500")
global e1
global e2

def Ok():
    call(["python", "Main.py"])



Label(root, text="Welcome").place(x=10, y=10)

Button(root, text="Add Student", command=Ok ,height = 3, width = 13).place(x=10, y=100)

root.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
tuts fun
  • 117
  • 1
  • 11

1 Answers1

1

Does this center your window?

from tkinter import *
from tkinter import messagebox
from subprocess import call

root = Tk()
root.title("Main")

window_width,window_height = 500,500

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

position_top = int(screen_height/2 - window_height/2)
position_right = int(screen_width / 2 - window_width/2)

root.geometry(f'{window_width}x{window_height}+{position_right}+{position_top}')

def Ok():
    pass

Label(root, text="Welcome").place(x=10, y=10)
Button(root, text="Add Student", command=Ok ,height = 3, width = 13).place(x=10, y=100)

root.mainloop()
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46