Reputation: 903
import tkinter as tk
from tkinter import ttk
win=tk.Tk()
def get_event(event):
print(f"{event.x} {event.y}")
win.bind("<Button-3>",get_event)
win.mainloop()
im making right click menu in tkinter but when i write event.x and event.y:
import tkinter as tk
from tkinter import ttk
win=tk.Tk()
menu=tk.Menu(win,tearoff=False)
menu.add_command(label="Nothing...")
def popup(event):
menu.tk_popup(event.x,event.y)
win.bind("<Button-3>",popup)
win.mainloop()
the menu overflows the window but when i write event.x_root and event.y_root in menu.tk_popup it doesn't
Upvotes: 3
Views: 3266
Reputation: 15098
When you use x
and y
attributes from event
, it refers to the x/y coordinate of the mouse at the time of the event, relative to the upper left corner of the widget.
But when you use x_root
and y_root
from event
, it refers to the x/y coordinate of the mouse at the time of the event, relative to the upper left corner of the screen.
Upvotes: 7