To start a Tkinter window at a specific point on the screen, you’ll need to use the geometry
method of the Tkinter window (i.e., Tk
or Toplevel
). This method allows you to set both the size and the position of the window. The format for the geometry
method is "<width>x<height>+<x_offset>+<y_offset>"
, where:
<width>
is the width of the window.<height>
is the height of the window.<x_offset>
is the horizontal distance from the left edge of the screen to the left edge of the window.<y_offset>
is the vertical distance from the top edge of the screen to the top edge of the window.import tkinter as tk def main(): # Create the main window root = tk.Tk() # Define the width, height, and position width = 300 height = 200 x_position = 100 y_position = 100 # Set the geometry of the window root.geometry(f"{width}x{height}+{x_position}+{y_position}") # Add a label to the window label = tk.Label(root, text="Hello, Tkinter!") label.pack(padx=20, pady=20) # Start the Tkinter event loop root.mainloop() if __name__ == "__main__": main()
In this example:
width and height are set to 300 and 200 pixels, respectively. The window will appear at coordinates (100, 100) on the screen.