Next: Freezing Tix Programs Up: Python Tix User Guide Previous: Public Variable Configuration

 

Using Tix with Python

As we have seen, Tix provides a rich widget set for designing user interfaces, and a simple object oriented framework for extending the widget repertoire with mega-widgets.

The Tkinter module is extended by Tix under Python by the module Tix.py. The Tix widgets are represented by a class hierarchy in Python with proper inheritance of base classes. We set up an attribute access function so that it is possible to access subwidgets in a standard fashion, using w.ok['text'] = 'Hello' rather than

w.subwidget('ok')['text'] = 'Hello'
when w is a StdButtonBox. We can even do w.ok.invoke() because w.ok is subclassed from the Button class if you go through the proper constructors.

In our example from the previous section, we would make our new mega-widget available to Python by extending the Tix module with the following class:

class ArrowButton(TixWidget):
  """ArrowButton - Demo Compound Widget.
  Subwidget Class
  --------- -----
  button    Button
  """
  def __init__(self, master, cnf={}, **kw):
      TixWidget.__init__(self, master,
               'tixArrowButton',
               ['options'], cnf, kw)
      self.subwidget_list['button'] = 
              _dummyButton(self, 'button')
  def flash(self):
      self.tk.call(self._w, 'flash')
  def invert(self):
      self.tk.call(self._w, 'invert')
  def invoke(self):
      self.tk.call(self._w, 'invoke')



http://tix.sourceforge.net