You can use the tkinter
library in Python to position windows. Here is an example code that positions a window at the center of the screen:
import tkinter as tk
root = tk.Tk()
# get screen width and height
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
# calculate x and y position for the window
x = (screen_width/2) - (300/2) # width of the window = 300
y = (screen_height/2) - (200/2) # height of the window = 200
# set the position of the window
root.geometry('%dx%d+%d+%d' % (300, 200, x, y))
root.mainloop()
The root.geometry()
method takes four parameters: width, height, x position, and y position. The %dx%d+%d+%d
format string is used to pass these parameters to the method. The x
and y
positions are calculated by subtracting half of the window size from the width and height of the screen respectively.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-16 11:08:31 +0000
Seen: 10 times
Last updated: Jul 16 '23
How can popen() be used to direct streaming data to TAR?
In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?
What is the method for merging field value and text into a singular line for display?
What is the method for programmatic access to a time series?