HavenRock.com: home
 
Asia ... Documentation ... Downloads ... DSSSL ... EFL/ESL ... HTML tools ... Linux ... Photography ... Python ... SGML ... Tcl/Tk ... TeX ... Tips ... Typography ... Word processing

The TrueFalseSwitch class

[ Get the code ]

A customized checkbutton widget for Tkinter that displays or outputs a boolean value according to a standardized or user-defined format. Here's how it looks with all options set to their default values.

TrueFalseSwitch: false TrueFalseSwitch: true

Purpose

This widget is intended to provide easy manipulation of boolean values, with a textual message indicating its state in addition to the checkbutton. Unlike the standard checkbutton, it takes the keyboard focus by default. The widget may be useful for such purposes as attribute editors where, for example, a large number of name-value pairs may be arrayed in a grid, with names in one column and values in the other.

Creating an instance of the class

Example:

    from Tkinter import *
    from tfswitch import TrueFalseSwitch
    tf = TrueFalseSwitch(win)
    tf.pack()
	      

Options

parent Required
A Tkinter window, such as win in the example above, that contains the TrueFalseSwitch.

displaystyle Optional
A string in the form "true_value/false_value". This determines how true and false values are displayed in the widget (not necessarily how they are returned to the application.
Defaults to "True/False"

outputstyle Optional
One of:

  • A string in the form "true_value/false_value"
  • The literal string "numeric"
  • "" (the empty string)

This determines how true and false values are returned to the application. A value of "numeric" causes the widget to return an integer value of 1 or 0. Note that this is different from "1/0", which will cause the widget to return a string consisting of "1" or "0". Setting this option to "" will cause the widget to use the values from displaystyle.
Defaults to "TRUE/FALSE".

initval Optional
The initial value for the widget.
Defaults to 0 (False).

Additional options
The usual Tkinter configuration options may be added to the end of the argument list, in name=value form.

Methods

The TrueFalseSwitch class provides two public methods, get() and set().


 
Matt Gushee

Last modified: Mon Dec 20 03:59:12 JST 1999