def __init__(self, master, values, command=None, args=(), variable=None, **kw): kw['style'] = 'TComboSmall' if variable is not None: kw['textvariable'] = variable self.variable = variable WidgetWithCommand.__init__(self) Widget.__init__(self, master, "ttk::menubutton", kw) if command: self.set_command(command, args) entries = [] for value in values: entries.append( ComboCommand(value, command=self.choose_opt, args=value)) self.__menu = ComboMenu(self, entries, auto_update=0, name="menu", tearoff=0) menu = self.__menu.menu self.menuname = menu._w self["menu"] = menu
def __init__(self, master, values, command = None, args = (), entry_type = 'text', **rest): kw = option_menu_defaults.copy() kw.update(rest) WidgetWithCommand.__init__(self) Widget.__init__(self, master, "menubutton", kw) self.widgetName = 'tk_optionMenu' if command: self.set_command(command, args) entries = [] value_dict = {} cfg = {'command' : self.choose_opt} for value in values: if type(value) == TupleType: text, value = value else: text = value value_dict[value] = text if not rest.has_key('initial'): rest['initial'] = value cfg[entry_type] = text cfg['args'] = (value,) entries.append(apply(MenuCommand, (), cfg)) self.__menu = UpdatedMenu(self, entries, auto_update = 0, name="menu", tearoff=0) menu = self.__menu.menu self.menuname = menu._w self["menu"] = menu self.entry_type = entry_type self.value_dict = value_dict if rest.has_key('initial'): self.SetValue(rest['initial'])
def __init__(self, master, variable, value, **kwargs): kw = {'borderwidth': 2, 'textvariable': variable, 'indicatoron': 1, 'relief': RAISED, 'anchor': 'c', 'highlightthickness': 2} Widget.__init__(self, master, 'menubutton', kw) self.var = variable self.widget_name = 'tk_optionmenu' self.__menu = Menu(self, name='menu', tearoff=0) self.menu_name = self.__menu._w self.callback = kwargs.get('command') if 'command' in kwargs: del kwargs['command'] if kwargs: raise TclError('unknown option -' + kwargs.keys()[0]) self.__menu.add_command(label=value, command=_SetIt(variable, value, self.callback)) self['menu'] = self.__menu
def __init__(self, master, values, command = None, args = (), variable = None, **kw): kw['style'] = 'TComboSmall' if variable is not None: kw['textvariable'] = variable self.variable = variable WidgetWithCommand.__init__(self) Widget.__init__(self, master, "ttk::menubutton", kw) if command: self.set_command(command, args) entries = [] for value in values: entries.append(ComboCommand(value, command = self.choose_opt, args = value)) self.__menu = ComboMenu(self, entries, auto_update = 0, name="menu", tearoff=0) menu = self.__menu.menu self.menuname = menu._w self["menu"] = menu
def __init__(self, master, values, command = None, args = (), variable = None): kw = option_menu_defaults.copy() if variable is not None: kw['textvariable'] = variable self.variable = variable WidgetWithCommand.__init__(self) Widget.__init__(self, master, "menubutton", kw) #self.widgetName = 'tk_optionMenu' if command: self.set_command(command, args) entries = [] for value in values: entries.append(MenuCommand(value, command = self.choose_opt, args = value)) self.__menu = UpdatedMenu(self, entries, auto_update = 0, name="menu", tearoff=0) menu = self.__menu.menu self.menuname = menu._w self["menu"] = menu
class WidgetTestCase(unittest.TestCase): def setUp(self): self.widget = Widget() def tearDown(self): self.widget.dispose() self.widget = None def testSize(self): self.assertEqual(self.widget.getSize(), (40, 40)) def testResize(self): self.widget.resize(100, 100) self.assertEqual(self.widget.getSize(), (100, 100))
def __init__(self, master=None, **kw): pax.register_object(self) kw['pyobject'] = id(self) kw['class'] = self.__class__.__name__ Widget.__init__(self, master, 'paxwidget', kw = kw)
def _unregister_event_handlers(self): Widget.unbind(self._view.canvas, '<Button-1>')
def _register_event_handlers(self): Widget.bind(self._view.canvas, '<Button-1>', self.mouse_click)
def __getitem__(self, name): if name == 'menu': return self.__menu.menu return Widget.__getitem__(self, name)
def __init__(self, master=None, **kw): key = pax.register_object(self) kw['pyobject'] = key kw['class'] = self.__class__.__name__ Widget.__init__(self, master, 'paxwidget', kw=kw) self.InitTkWinObject(pax.name_to_window(self._w, self.tk.interpaddr()))
def __init__(self, master=None, **kw): key = pax.register_object(self) kw['pyobject'] = key kw['class'] = self.__class__.__name__ Widget.__init__(self, master, 'paxwidget', kw = kw) self.InitTkWinObject(pax.name_to_window(self._w, self.tk.interpaddr()))
# Getting the parent of a parent widget in Python Tkinter parent = event.widget.winfo_parent() from Tkinter import Widget Widget._nametowidget(parent)
def setUp(self): self.widget = Widget()
def __init__(self, master=None, **kw): Widget.__init__(self, master, "ttk::combobox", kw) self.bind("<Key>", lambda e: "break") # Magic
def _unregister_event_handlers(self): if not isinstance(self._view.canvas, TrainingCanvas): Widget.unbind(self._view.canvas, '<Button-1>')