| 2453 | |
| 2454 | class MutableOptionMenu(Menubutton): |
| 2455 | def __init__(self, master, values, **options): |
| 2456 | self._callback = options.get("command") |
| 2457 | if "command" in options: |
| 2458 | del options["command"] |
| 2459 | |
| 2460 | # Create a variable |
| 2461 | self._variable = variable = StringVar() |
| 2462 | if len(values) > 0: |
| 2463 | variable.set(values[0]) |
| 2464 | |
| 2465 | kw = { |
| 2466 | "borderwidth": 2, |
| 2467 | "textvariable": variable, |
| 2468 | "indicatoron": 1, |
| 2469 | "relief": RAISED, |
| 2470 | "anchor": "c", |
| 2471 | "highlightthickness": 2, |
| 2472 | } |
| 2473 | kw.update(options) |
| 2474 | Widget.__init__(self, master, "menubutton", kw) |
| 2475 | self.widgetName = "tk_optionMenu" |
| 2476 | self._menu = Menu(self, name="menu", tearoff=0) |
| 2477 | self.menuname = self._menu._w |
| 2478 | |
| 2479 | self._values = [] |
| 2480 | for value in values: |
| 2481 | self.add(value) |
| 2482 | |
| 2483 | self["menu"] = self._menu |
| 2484 | |
| 2485 | def add(self, value): |
| 2486 | if value in self._values: |