开发者

Get label value from dynamically created menu items [tkinter]

开发者 https://www.devze.com 2023-04-08 13:47 出处:网络
I have a cascade menu in a parent menu. The cascade items are created dynamically with add_checkbutton method.

I have a cascade menu in a parent menu. The cascade items are created dynamically with add_checkbutton method.

A user should be able to "check" menu items and select/confirm them. However, I don't know how to access text in the menu items, to decide which item is selected.

Obvious solution is开发者_开发百科 to generate tk.StringVar dynamically, but I would like to avoid that since it complicates the code significantly.

How to get value of the menu label/text in tkinter? Is there other solution to the problem?


You can use the entrycget method of a menu item to get any of its attributes, including the label and value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号