Table of Contents
This has the definition for the GCheckBox widget. The GCheckBox widget provides you with the ability to have a small checkbox and associated text, as well as listen for a user toggle event. A toggle occurs when the user checks or unchecks the GCheckBox widget.
This widget is RTV enabled (see grail.rtv).
The following example creates a GCheckBox widget on a very simple window.
If you ran the above code you would get the following Tkinter window.
Example of the GCheckBox widget.
This example displays to main features.
Associates RTV variable with a widget.
The state of the widget is maintained after the window has been destroyed by the user. When the mainloop function quits, the window has been destroyed, and we can query the use_multiore RTV to determine what we should print to the screen.
Ability to listen to toggle events.
Via the grail.objsignal module we are able to listen to the GCheckBox and determine if there are user events occurring. Whenever the user clicks on the GCheckBox the on_toggle() function is executed.
When working with floating point numbers it is NOT recommended to insert raw floating point numbers into the GComboBox, instead prefer to store string representations of the floating point numbers.
There is a problem comparing floating point numbers accurately on a computer, and that can make it difficult to local an item within the GComboBox.
However, if you manage how you want to represent the floating point, and convert it to a string, and always make your comparisons with string representations you have a much better chance of locating an item in the list.
class GCheckBox([parent, **keywords])
In many respects this widget is similar to the Checkbutton widget [1] that is imported with Tkinter [2]. However, there are a few differences between the two that should be noted. The following Tkinter Checkbutton options are disabled not available,
The 'state' option is disabled for a GCheckBox. To set the state of a GCheckBox use the enable or disable functions.
The toggle state is modified via the 'togglestate' configuration option. For example,
cb = GCheckBox(root)
cb['togglestate'] = 1Would set the checkbox to an on position.
The 'variable' option for a Tkinter.Checkbutton is not available.
In addition, the RTV variable can not be configured after the GCheckBox has be initialized.
- Keywords:
Same as Tkinter.Checkbutton except where noted above and the following,
- rtv
- A grail.rtv variable that you wish to associate with the GCheckbox.
- Signal:
const.sigON_TOGGLE
Emitted whenever the checkbox is clicked; this signal delivers the state of the widget along with it. Your callback should have the following signature: ontoggle(state).- Components:
- None.
- causetoggleevent()
Mainly for testing purposes. Generates a toggle event.
Toggles the state of the check button, and generates all the appropriate signals, just like a user clicked the check button.
The preferred method for altering the toggle state is via the modification of the togglestate variable,
cb = GCheckBox(root)
cb['togglestate'] = 1- destroy()
- Handles the Tkinter clean-up request.
- disable()
- Set the checkbox to ignore user events.
- enable()
- Set the checkbox to respond to user events.
- updatevars()
Synchronizes the GUI with the variables.
In this case, the very definition of a check box implies that the internal variables are constantly in synchronized. So in this case we always return 1.
[1] | Fredrik Lundh. "The Checkbutton Widget" An Introduction to Tkinter. 1999. June 9 2004. <http://www.pythonware.com/library/tkinter/introduction/checkbutton.htm> |
[2] | Fredrik Lundh. An Introduction to Tkinter. 1999. June 9 2004. <http://www.pythonware.com/library/tkinter/introduction/> |