python - How to get tkinter menubar label Value? -


i have looked lot can`t find answer, below example:

menu.add_command(label='abc',command=callback) 

how can 'abc' variable?

you can use entrycget() , pass "label" option.

here short example demonstrate how works:

import tkinter tk   def callback(menu):     x= menu.entrycget(0, "label")     print(x) # print "abc" in terminal   root = tk.tk() menu_bar = tk.menu(root) file_menu = tk.menu(menu_bar, tearoff=false) file_menu.add_command(label="abc", command=lambda: callback(file_menu)) menu_bar.add_cascade(label="file", menu=file_menu) root.config(menu=menu_bar) root.mainloop() 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -