Reputation: 11
I am facing this issue where whenever I try to trigger the activate() method by clicking the command inside the Menu widget, I am not able to see the method in action because by default the Menu widget will close automatically when I click any of its command.
Here is my code:
import tkinter as tk
def on_open():
print("Stop1")
file_menu.activate(1) # Automatically highlight the 'Save' option
print("Stop2")
root = tk.Tk()
root.geometry("400x200")
menu_bar = tk.Menu(root)
root.config(menu=menu_bar)
file_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Open", command=on_open)
file_menu.add_command(label="Save", command=lambda: print("Save selected"))
file_menu.add_command(label="Exit", command=root.quit)
root.mainloop()
Does anyone has any idea how to effectively use the activate() of Menu widget class without closing the Menu widget?
Upvotes: 1
Views: 48