Page 366 -
P. 366

graphical interface elements


          The checkbox is an on/off, flip/flop toggle


           The great thing about the checkbox graphical interface element is that it can
           be in only one of two states, either on or off. Depending on the current state
           of the checkbox, an object can be set to either 1 for “on” or 0 for “off.”



                                                   Whoo hoo! Set
                                                  that object to
                                                  1, baby!




                                                                                    Set me, checkbox,
           Click the checkbox                                                       set me... I can be
           to “tick” it and set                                                     either 1 or 0.
           the object to “on”.










           Click the checkbox to
          “untick” it and set the
           object to “off”.





                                                  Ah, phooey! Set
                                                   that object to 0,
                                                  which is, like, oooh.






           In tkinter, checkboxes are created using Checkbutton(), and they can be
           associated with a tkinter IntVar, first introduced in Chapter 7. The tkinter
           Checkbutton() is either on or off and sets the associated IntVar to
           either 1 or 0, which is perfect for what you need.

           Let’s look at using a checkbox in tkinter.



                                                                                       you are here 4    331
   361   362   363   364   365   366   367   368   369   370   371