MCPcopy Index your code
hub / github.com/python/cpython / OptionMenu

Class OptionMenu

Lib/tkinter/ttk.py:1584–1648  ·  view source on GitHub ↗

Themed OptionMenu, based after tkinter's OptionMenu, which allows the user to select a value from a menu.

Source from the content-addressed store, hash-verified

1582
1583
1584class OptionMenu(Menubutton):
1585 """Themed OptionMenu, based after tkinter's OptionMenu, which allows
1586 the user to select a value from a menu."""
1587
1588 def __init__(self, master, variable, default=None, *values, **kwargs):
1589 """Construct a themed OptionMenu widget with master as the parent,
1590 the option textvariable set to variable, the initially selected
1591 value specified by the default parameter, the menu values given by
1592 *values and additional keywords.
1593
1594 WIDGET-SPECIFIC OPTIONS
1595
1596 style: stylename
1597 Menubutton style.
1598 direction: 'above', 'below', 'left', 'right', or 'flush'
1599 Menubutton direction.
1600 command: callback
1601 A callback that will be invoked after selecting an item.
1602 """
1603 kw = {'textvariable': variable, 'style': kwargs.pop('style', None),
1604 'direction': kwargs.pop('direction', None),
1605 'name': kwargs.pop('name', None)}
1606 Menubutton.__init__(self, master, **kw)
1607 self['menu'] = tkinter.Menu(self, tearoff=False)
1608
1609 self._variable = variable
1610 self._callback = kwargs.pop('command', None)
1611 if kwargs:
1612 raise tkinter.TclError('unknown option -%s' % (
1613 next(iter(kwargs.keys()))))
1614
1615 self.set_menu(default, *values)
1616
1617
1618 def __getitem__(self, item):
1619 if item == 'menu':
1620 return self.nametowidget(Menubutton.__getitem__(self, item))
1621
1622 return Menubutton.__getitem__(self, item)
1623
1624
1625 def set_menu(self, default=None, *values):
1626 """Build a new menu of radiobuttons with *values and optionally
1627 a default value."""
1628 menu = self['menu']
1629 menu.delete(0, 'end')
1630 for val in values:
1631 menu.add_radiobutton(label=val,
1632 command=(
1633 None if self._callback is None
1634 else lambda val=val: self._callback(val)
1635 ),
1636 variable=self._variable)
1637
1638 if default:
1639 self._variable.set(default)
1640
1641

Callers 1

create_page_windowsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…