1

I have a top level window that has been created using tkinter. When I set the geometry, the app is not positioned as I would expect.

import tkinter as tk
root = tk.Tk()
root.geometry("500x500+0+0")
root.mainloop()

After running the above code, the window is off by a small amount (7 pixels). I found this out by printing the x and y values after maximizing the window.

def print_coordinates_of_window_when_state_is_zoomed(root):
    print(root.winfo_x())  # prints -7
    print(root.winfo_y())  # prints 0

Is there a way to fix this? Alternatively, will any Windows PC have the same offset (i.e. -7)?

1 Answers1

0

This is because of the window manager of your operating system you can proof it by this code here:

import tkinter as tk
root = tk.Tk()
root.overrideredirect(1)
root.geometry("500x500+0+0")
root.mainloop()

If you remove overrideredirect(1) you will notice that the offset is that space where your mouse can resize your window.

to get rid of the problem without using overrideredirect just use -

import tkinter as tk
root = tk.Tk()
root.geometry("500x500+-7+0")
root.mainloop()

For more

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
  • Thanks for the reply. I just tried this out. It does get rid of the gap between the edge of the screen and the window but then I can't use the normal quit, minimize and resize buttons in the top-right corner of the window. Is there some way to work around this? – Muhaimin Khan Oct 09 '20 at 17:47