Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position topLevel() widget relative to root window?

I have created a topLevel widget and was wondering if there was a way to position the new window relative to the root window.

like image 758
Tom Boy Avatar asked Mar 17 '16 01:03

Tom Boy


People also ask

What is a toplevel widget?

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.

What is a toplevel window?

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.

How do I know if a toplevel exists?

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.


1 Answers

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.

like image 171
Kenly Avatar answered Sep 21 '22 18:09

Kenly