Construct an optionmenu widget with the parent MASTER, with the option textvariable set to VARIABLE, the initially selected value VALUE, the other menu values VALUES and an additional keyword argument command.
(self, master, variable, value, *values, **kwargs)
| 4302 | """OptionMenu which allows the user to select a value from a menu.""" |
| 4303 | |
| 4304 | def __init__(self, master, variable, value, *values, **kwargs): |
| 4305 | """Construct an optionmenu widget with the parent MASTER, with |
| 4306 | the option textvariable set to VARIABLE, the initially selected |
| 4307 | value VALUE, the other menu values VALUES and an additional |
| 4308 | keyword argument command.""" |
| 4309 | kw = {"borderwidth": 2, "textvariable": variable, |
| 4310 | "indicatoron": 1, "relief": RAISED, "anchor": "c", |
| 4311 | "highlightthickness": 2, "name": kwargs.pop("name", None)} |
| 4312 | Widget.__init__(self, master, "menubutton", kw) |
| 4313 | self.widgetName = 'tk_optionMenu' |
| 4314 | menu = self.__menu = Menu(self, name="menu", tearoff=0) |
| 4315 | self.menuname = menu._w |
| 4316 | # 'command' is the only supported keyword |
| 4317 | callback = kwargs.get('command') |
| 4318 | if 'command' in kwargs: |
| 4319 | del kwargs['command'] |
| 4320 | if kwargs: |
| 4321 | raise TclError('unknown option -'+next(iter(kwargs))) |
| 4322 | menu.add_command(label=value, |
| 4323 | command=_setit(variable, value, callback)) |
| 4324 | for v in values: |
| 4325 | menu.add_command(label=v, |
| 4326 | command=_setit(variable, v, callback)) |
| 4327 | self["menu"] = menu |
| 4328 | |
| 4329 | def __getitem__(self, name): |
| 4330 | if name == 'menu': |