how to return button position
import tkinter as tk
def do_popup():
root.menu.post(??,??)
root = tk.Tk()
root.btn1 = tk.Button(root, text="POPUP", command=do_popup)
root.btn1.grid(row=1, column=1)
root.menu = tk.Menu(root, tearoff=0)
root.menu.add_command(label="a")
root.menu.add_command(label="b")
root.menu.add_command(label="c")
how to get the POPUP button's x and y ???
You're looking for Tkinter's winfo_rootx()
and winfo_rooty()
methods, which return pixel coordinates relative to the screen's upper left corner.
def do_popup():
x, y = root.btn1.winfo_rootx(), root.btn1.winfo_rooty()
print (x, y)
More: http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.winfo_rootx-method
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.