78 | | == Check Boxes == |
| 78 | == Check Buttons == |
| 79 | |
| 80 | A check button has a label and a tick box; clicking on the button will tick or untick the box. The checkbutton's state is stored in its attribute 'active'. An example of a check button: |
| 81 | |
| 82 | [[Image(checkbutton.png)]] |
| 83 | |
| 84 | (To use this code, replace the 'createWidgets' method in the above example, and add the field definition.) |
| 85 | |
| 86 | {{{ |
| 87 | #!cobra |
| 88 | var _checkbutton as CheckButton # store the check button as a field |
| 89 | |
| 90 | def createWidgets |
| 91 | _checkbutton = CheckButton("select") # create the check button |
| 92 | |
| 93 | # Create a button to print out state of other widgets |
| 94 | button = Button("Show State") |
| 95 | # associate action when clicked |
| 96 | listen button.clicked, ref .showState |
| 97 | |
| 98 | # Add the two buttons to the window within a box |
| 99 | box = VBox(true, 0) |
| 100 | box.packStart(_checkbutton, false, false, 20) |
| 101 | box.packStart(button, false, false, 20) |
| 102 | |
| 103 | .add(box) |
| 104 | |
| 105 | def showState(obj, e) |
| 106 | print "Check button state is", _checkbutton.active # report the check button's state |
| 107 | }}} |