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

Scrollbar
          If you shrink down the window for the program 07_06_resizing.py, you will notice that there’s no
          scrollbar to access text that’s hidden. You can still get to the text, but clearly a scrollbar would help.
             Scrollbars are widgets in their own right, and the trick for making them work with something like a
          Text, Message, or Listbox widget is to lay them out next to each other and then link them together.
             Figure 7-8 shows a Text widget with a scrollbar.


































          Figure 7-8    Scrolling a Text widget
             The code for this is as follows:




























             In this example, we use the pack layout, positioning the scrollbar on the right and the text area on
          the left. The fill attribute specifies that the Text widget is allowed to use all free space on both the X
          and Y dimensions.

             To link the scrollbar to the Text widget, we set the yscrollcommand property of the Text widget to
          t h e set  method  of  the  scrollbar. Similarly,  the  command  attribute  of  the  scrollbar  is  set  to
          text.yview.
          Dialogs
          It is sometimes useful to pop up a little window with a message and make the user click OK before
          they can do anything else (see Figure 7-9). These windows are called modal dialogs, and Tkinter has a
   71   72   73   74   75   76   77   78   79   80   81