Answers for "how to make a python window be in the center of the screen"

1

python center main window on screen

# Centering Root Window on Screen
 
from tkinter import * 
 
root = Tk()
 
# Gets the requested values of the height and widht.
windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()
print("Width",windowWidth,"Height",windowHeight)
 
# Gets both half the screen width/height and window width/height
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)
 
# Positions the window in the center of the page.
root.geometry("+{}+{}".format(positionRight, positionDown))
 
 
root.mainloop()
Posted by: Guest on May-25-2021
1

python center window

import os
os.environ["SDL_VIDEO_CENTERED"] = "1"
Posted by: Guest on September-11-2020

Code answers related to "how to make a python window be in the center of the screen"

Python Answers by Framework

Browse Popular Code Answers by Language