How to start Tkinter window at a specific position of your display

In this tutorial, we will learn how to start the Tkinter window at a specific position of your display.

It’s much simpler than we think.

Let’s first create a simple window.

import tkinter as tk
newWindow = tk.Tk()
newWindow.title("CodeSpeedy")
newWindow.mainloop()

The output will be like this:

Tkinter sample window

As you can see, my window has been started at the top left corner of my display.

If you see it like math, then the coordinates of that position are x=0 and y=0

The syntax to change the coordinates is:

newWindow.geometry("widthxheight+x+y")

Let’s explain the parameters:

  1. width is our tkinter window width.
  2. height is our tkinter window height.
  3. x and y are the window opening position when we run the program.
    x is the x coordinate of the display and y is the y coordinate of the display. So by setting these values, we can position our window anywhere we want.

(Special note: you can also use negative values for X and Y, if it reaches the end of your display, it will count from the totally opposite side of your display after that. You can try it yourself.

Let’s learn through an example.

Suppose we want our window size to be 600×400 and the starting Tkinter window position should be x=700 and y= 600.

import tkinter as tk
newWindow = tk.Tk()
newWindow.title("CodeSpeedy")
newWindow.geometry("600x400+700+600")
newWindow.mainloop()

Output:

start tkinter window at a specific position of your display

You can play around with your x and y values to change the position.

X and Y are nothing but the pixel value of your display.

You can also watch the video tutorial of this topic:

Leave a Reply

Your email address will not be published. Required fields are marked *