1 year ago
#55532
srccircumflex
How to use tk.menu.unpost under windows
The question is how to use the tk.menu.unpost method under windows.
The code:
if __name__ == "__main__":
from tkinter import Menu, Tk, Label
t = Tk()
label = Label(t, text="Label")
label.pack()
menu = Menu(t, tearoff=0)
menu.add_command(label="command")
def unpost(event=None):
print(event)
menu.unpost()
def post(event=None):
print(event)
menu.after(3000, unpost)
try:
menu.tk_popup(menu.winfo_pointerx(), menu.winfo_pointery())
finally:
menu.grab_release()
label.bind("<Button-3>", post)
t.bind("<u>", unpost)
label.bind("<u>", unpost)
menu.bind("<u>", unpost)
t.mainloop()
On Linux, the unpost method works when triggered by the events or via menu.after. On the windows platform the keybindings are apparently suppressed, the function unpost is executed as desired after three seconds, nevertheless the call remains eventless.
python-3.x
windows
popup
tk-toolkit
tkinter-menu
0 Answers
Your Answer