tkinter optionmenu first option vanishes

前端 未结 5 1793
面向向阳花
面向向阳花 2020-12-05 08:00

A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear...

Does

5条回答
  •  无人及你
    2020-12-05 08:39

    The signature of the ttk.OptionMenu command is this:

    def __init__(self, master, variable, default=None, *values, **kwargs):
    

    This is the docstring:

    """Construct a themed OptionMenu widget with master as the parent, the resource textvariable set to variable, the initially selected value specified by the default parameter, the menu values given by *values and additional keywords.

    Notice the default option which comes before the list of values. Instead of adding a blank item to the list of values, add whichever value you want as the default:

    options = ['1', '2', '3']
    dropdown = ttk.OptionMenu(masterframe, value, options[1], *options)
    

提交回复
热议问题