Page 72 - Programming the Raspberry Pi Getting Started with Python
P. 72

For the sake of efficiency, it is better if we create a single “converter” during __init__ and just use
          the same one every time the button is clicked. Therefore, we create a variable called self.t_conv to
          reference the convertor. The convert method then just becomes this:






             Here is the full listing of the program:











































          Other GUI Widgets
          In the temperature converter, we just used text fields (class Entry) and labels (class Label). As you
          would  expect,  you  can  build  lots  of  other  user  interface  controls  into  your  application. Figure  7-5
          shows the main screen of a “kitchen sink” application that illustrates most of the controls you can use
          in Tkinter. This program is available as 07_05_kitchen_sink.py.

















          Figure 7-5   A “kitchen sink” application
          Checkbutton
          The Checkbox widget (first column, second row of Figure 7-5) is created like this:


             This line of code just creates a Checkbutton with a label next to it. If we have gone to the effort of
          placing a check box on the window, we’ll also want a way of finding out whether or not it is checked.
   67   68   69   70   71   72   73   74   75   76   77