ttk.OptionMenu() displaying check mark on all menus

牧云@^-^@ 提交于 2019-12-02 05:15:32

This is a bug in the ttk implementation of OptionMenu. It isn't assigning a unique variable for the radiobuttons in each OptionMenu.

You can fix this with a little bit of code. Basically, you have to loop over every item in the menu and set the variable attribute.

Here's an example:

def optionmenu_patch(om, var):
    menu = om['menu']
    last = menu.index("end")
    for i in range(0, last+1):
        menu.entryconfig(i, variable=var)
...
for each in range(10):
    sv = StringVar()
    om = OptionMenu(root, sv, choices[0], *choices)
    om.pack()
    optionmenu_patch(om, sv)

Bug tracker issue: http://bugs.python.org/issue25684

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!