Tkinter: How can I determine the position of a Toplevel?
python, python-3.x, tkinter
Solution
You can get the window's position through the `winfo_x` and `winfo_y` methods.
Below is a simple script to demonstrate*:
from tkinter import Tk, Button
root = Tk()
def click():
print(root.winfo_x(), root.winfo_y())
Button(text="Get position", command=click).grid()
root.mainloop()
*Note: I used a `Tk` window here instead of a `Toplevel` for the sake of simplicity. However, the same principle applies to the `Toplevel`.
Problem
The title says it all really, I have a piece of code in which I would like to move the top-level in relation to its old position. To do this I need to fetch the current position of the window, then set the new position using `root.geometry('+x+y')`. How can I find the current position of a TopLevel?