Pmw.RadioSelect

Name

Pmw.RadioSelect() - a set of buttons, some of which may be selected

Inherits

Pmw.MegaWidget

Description

This class creates a manager widget for containing buttons. In single selection mode, only one button may be selected at any one time. In multiple selection mode, several buttons may be selected. Selected buttons are displayed sunken. The buttons may be laid out either horizontally or vertically.

Options

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

command
Specifies a function to call whenever a button is invoked, either by clicking on it or by calling invoke().

If selectmode is 'single', then the function is called with a single argument, which is the name of the button which was invoked.

If selectmode is 'multiple', then the function is called with the first argument being the name of the button which was invoked and the second argument being either 0 or 1 depending on whether the button is currently selected. The default is None.

labelmargin
Initialisation option. If the labelpos option is not None, this specifies the distance between the label component and the rest of the megawidget. The default is 0.

labelpos
Initialisation option. Specifies where to place the label component. If not None, it should be a concatenation of one or two of the letters 'n', 's', 'e' and 'w'. The first letter specifies on which side of the megawidget to place the label. If a second letter is specified, it indicates where on that side to place the label. For example, if labelpos is 'w', the label is placed in the centre of the left hand side; if it is 'wn', the label is placed at the top of the left hand side; if it is 'ws', the label is placed at the bottom of the left hand side.

If None, a label component is not created. The default is None.

orient
Initialisation option. Specifies the direction in which the buttons are laid out. 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 radio select widget. The default is 5.

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 radio select widget. The default is 5.

selectmode
Initialisation option. Specifies whether a single button only or multiple buttons can be selected at one time. If 'single', clicking on an unselected button selects it and deselects all other buttons. If 'multiple', clicking on an unselected button selects it and clicking on a selected button deselects it. The default is 'single'.

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() method. 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 the widget. By default, this component is a Tkinter.Frame.

label
If the labelpos option is not None, this component is created as a text label for the megawidget. See the labelpos option for details. Note that to set, for example, the text option of the label, you need to use the label_text component option. By default, this component is a Tkinter.Label.

Dynamic components

Button components are created dynamically by the add() method. 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 manuals for its base classes.

add(name, **kw)
Add a button to the end of the radio select widget as a component named name. Any keyword arguments present (except command) 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 name. The method returns the name component widget.

deleteall()
Delete all buttons and clear the current selection.

getcurselection()
If selectmode is 'single', return the name of the currently selected button, or None if no buttons have been selected yet.

If selectmode is 'multiple', return a list of the names of the currently selected buttons.

index(index)
Return the numerical index of the button corresponding to index. This may be specified in any of the following forms:

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

end
Indicates the right (or bottom) button.

name
Specifies the button named name.

invoke(index)
Calling this method is the same as clicking on the button specified by index. If selectmode is 'single', then the current selection is set to the name of the button, the button is displayed sunken, all other buttons are raised, and the function specified by the command option is called with the name of the button as the single argument.

If selectmode is 'multiple' and the button has been selected, then the name of the button is appended to the current selection, the button is displayed sunken and the function specified by the command option is called with the name of the button as the first argument and 1 as the second argument.

If selectmode is 'multiple' and the button has been deselected, then the name of the button is removed from the current selection, the button is displayed raised and the function specified by the command option is called with the name of the button as the first argument and 0 as the second argument.

See the index() method for the format of index.

numbuttons()
Return the number of buttons in the radio select widget.

Home. Pmw 0.7 Maintainer gregm@iname.com. 2 Jun 1998