Pmw.ButtonBox reference manual
Description: Pmw - a toolkit for building high-level compound widgets in Python

# Pmw.ButtonBox

### Name

  Pmw.ButtonBox() - manager megawidget for buttons

### Inherits

  Pmw.MegaWidget

### Description

  A button box is a container megawidget which manages a number of buttons. One of these buttons may be specified as the default and it will be displayed with the platform specific appearance for a default button. The buttons may be laid out either horizontally or vertically.

### Options

  Options for this megawidget and its base classes are described below.

  labelmargin
    Initialisation option. The default is 0.
  labelpos
    Initialisation option. The default is None.
  orient
    Initialisation option. Specifies the orientation of the button box. This may be 'horizontal' or 'vertical'. The default is 'horizontal'.
  padx
    Initialisation option. Specifies a padding distance to leave between each button in the x direction and also between the buttons and the outer edge of the button box. The default is 3.
  pady
    Initialisation option. Specifies a padding distance to leave between each button in the y direction and also between the buttons and the outer edge of the button box. The default is 3.

### Components

  Components created by this megawidget and its base classes are described below.

  frame
    If the label component has been created (that is, the labelpos option is not None), the frame component is created to act as the container of the buttons created by the `add()` and `insert()` methods. If there is no label component, then no frame component is created and the hull component acts as the container. By default, this component is a Tkinter.Frame.
  hull
    This acts as the body for the entire megawidget. Other components are created as children of the hull to further specialise this class. By default, this component is a Tkinter.Frame.
  label
    By default, this component is a Tkinter.Label.

### Dynamic components

  Button components are created dynamically by the `add()` and `insert()` methods. By default, the buttons are of type Tkinter.Button and are created with a component group of Button.

### Methods

  Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manual for its base class Pmw.MegaWidget.

  add(componentName,**kw)
    Add a button to the end of the button box as a component named componentName. Any keyword arguments present will be passed to the constructor when creating the button. If the text keyword argument is not given, the text option of the button defaults to componentName. The method returns the component widget.
  alignbuttons(when = 'later')
    Set the widths of all the buttons to be the same as the width of the widest button. If when is 'later', this will occur when the interpreter next becomes idle, otherwise the resizing will occur immediately.
  button(buttonIndex)
    Return the button specified by buttonIndex, which may have any of the forms accepted by the `index()` method.
  delete(index)
    Delete the button given by index from the button box. index may have any of the forms accepted by the `index()` method.
  index(index,forInsert = 0)
    Return the numerical index of the button corresponding to index. This may be specified in any of the following forms:
    name
      Specifies the button named name.

    number
      Specifies the button numerically, where 0 corresponds to the left (or top) button.

    Pmw.END
      Specifies the right (or bottom) button.

    Pmw.DEFAULT
      Specifies the current default button.

    If forInsert is true, Pmw.END returns the number of buttons rather than the index of the last button.

  insert(componentName,beforeComponent = 0,**kw)
    Add a button to the button box as a component named componentName. The button is added just before the button specified by beforeComponent, which may have any of the forms accepted by the `index()` method. Any keyword arguments present will be passed to the constructor when creating the button. If the text keyword argument is not given, the text option of the button defaults to componentName. To add a button to the end of the button box, use `add()`. The method returns the component widget.
  invoke(index = Pmw.DEFAULT,noFlash = 0)
    Invoke the callback command associated with the button specified by index and return the value returned by the callback. Unless noFlash is true, flash the button to indicate to the user that something happened. index may have any of the forms accepted by the `index()` method.
  numbuttons()
    Return the number of buttons in the button box.
  setdefault(index)
    Set the default button to the button given by index. This causes the specified button to be displayed with the platform specific appearance for a default button. If index is None, there will be no default button. index may have any of the forms accepted by the `index()` method.

### Example

  The image at the top of this manual is a snapshot of the window (or part of the window) produced by the following code.

      class Demo:
          def __init__(self, parent):
              # Create and pack the ButtonBox.
              self.buttonBox = Pmw.ButtonBox(parent,
                      labelpos = 'nw',
                      label_text = 'ButtonBox:',
                      frame_borderwidth = 2,
                      frame_relief = 'groove')
              self.buttonBox.pack(fill = 'both', expand = 1, padx = 10, pady = 10)

              # Add some buttons to the ButtonBox.
              self.buttonBox.add('OK', command = self.ok)
              self.buttonBox.add('Apply', command = self.apply)
              self.buttonBox.add('Cancel', command = self.cancel)

              # Set the default button (the one executed when <Return> is hit).
              self.buttonBox.setdefault('OK')
              parent.bind('<Return>', self._processReturnKey)
              parent.focus_set()

              # Make all the buttons the same width.
              self.buttonBox.alignbuttons()

          def _processReturnKey(self, event):
              self.buttonBox.invoke()

          def ok(self):
              print('You clicked on OK')

          def apply(self):
              print('You clicked on Apply')

          def cancel(self):
              print('You clicked on Cancel')

Pmw 2.0.0 - 29 Mar 2014 - Home
Manual page last reviewed: 24 May 1998