Tkinter setting wrong window position at top left corner

Hi!
I am trying to locate a window at top left corner with this code:

import tkinter as tk
root = tk.Tk()
root.geometry("400x400+0+0")
root.mainloop()

However, this always left a gap in x axis. It does not move to x=0 (see image).

Could you please help me with that? I don´t want to use an artificial offset. And I am going crazy at this point failing at this super-simple task.

Python Version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]

Thank you very much!

It’s a known issue on Windows. It’s Windows itself that’s doing it. The only time it doesn’t happen is when the widget state is “zoomed”.

It can also happen on Linux, too, depending on the setup.

The cause of this seems to be that Microsoft made the window borders partially invisible in Windows 10:

So the left edge of the border is at x=0 as expected, you just can’t see it. I guess that also explains why the mouse cursor changes to the resize symbol before it visibly touches the window.

The StackOverflow post suggests offsetting by 7 pixels. If you don’t want to hardcode it, you can supposedly (but I haven’t tested this) get this value from the GetSystemMetrics function, which you can call via ctypes. Something like this (untested):

import ctypes
import tkinter as tk

user32 = ctypes.windll.user32
SM_CXSIZEFRAME = 32
SM_CYSIZEFRAME = 33

border_width = user32.GetSystemMetrics(SM_CXSIZEFRAME)
border_height = user32.GetSystemMetrics(SM_CYSIZEFRAME)

root = tk.Tk()
root.geometry(f"400x400+-{border_width}+-{border_height}")
root.mainloop()

Thank you very much Henrik and Matthew!
What an awkward thing to do!
I think the easiest thing to do is to apply an offset of -8 manually, which is exactly what I didn’t want to do, as I thought I was making a mistake or had a problem in my configuration.
Thanks again!