简体   繁体   中英

Tkinter Toplevel() positioning without static geometry

Im using Toplevel() for popup windows and I want the popup to be displayed to the right of the mouse when it comes up. I found how to do this but only by specifying the geometry of the window. How can I control where the window comes up without specifying the size. I want the window to be the size it needs to be for whatever data is is going to display.

This is what im using right now:

helpwindow = Toplevel()
helpwindow.overrideredirect(1)
helpwindow.geometry("662x390+{0}+{1}".format(event.x_root - 1, event.y_root - 12))

How can I put only the format settings in the window geometry? Or is their a better way?

Use "+{}+{}" without size

helpwindow.geometry("+{}+{}".format(event.x_root - 1, event.y_root - 12))

ie. moving window :)

import tkinter as tk

def move():
    global pos_x

    helpwindow.geometry("+{}+200".format(pos_x))
    pos_x += 10

    root.after(100, move)

root = tk.Tk()

pos_x = 0    
helpwindow = tk.Toplevel()
move()

root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM