I have created a topLevel widget and was wondering if there was a way to position the new window relative to the root window.
The Toplevel widget is used to create and display the toplevel windows which are directly managed by the window manager. The toplevel widget may or may not have the parent window on the top of them.
A top-level form is a window that has no parent form, or whose parent form is the desktop window. Top-level windows are typically used as the main form in an application.
You can check whether a top level exists using ' tkinter. Toplevel. winfo_exists(my_toplevel_name) '. If you put this in a print statement, it returns 1 if it does exist, and 0 if it does not.
Get root
window position:
x = root.winfo_x()
y = root.winfo_y()
Use geometry
to set the position:
w = toplevel.winfo_width()
h = toplevel.winfo_height()
toplevel.geometry("%dx%d+%d+%d" % (w, h, x + dx, y + dy))
where dx
and dy
are the offsets from the current position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With