Page 204 - thinkpython
P. 204

182                                               Chapter 19. Case study: Tkinter

                  item.config(fill=  'yellow ', outline= 'orange ', width=10)
                  width is the thickness of the outline in pixels; outline is the color.
                  Exercise 19.2. Write a program that creates a Canvas and a Button. When the user presses the
                  Button, it should draw a circle on the canvas.




                  19.4    Coordinate sequences

                  The rectangle method takes a sequence of coordinates that specify opposite corners of the
                  rectangle. This example draws a blue rectangle with the lower left corner at the origin and
                  the upper right corner at (200, 100):
                  canvas.rectangle([[0, 0], [200, 100]],
                                    fill= 'blue ', outline= 'orange ', width=10)
                  This way of specifying corners is called a bounding box because the two points bound the
                  rectangle.

                  oval takes a bounding box and draws an oval within the specified rectangle:
                  canvas.oval([[0, 0], [200, 100]], outline=  'orange ', width=10)
                  line takes a sequence of coordinates and draws a line that connects the points. This exam-
                  ple draws two legs of a triangle:
                  canvas.line([[0, 100], [100, 200], [200, 100]], width=10)
                  polygon takes the same arguments, but it draws the last leg of the polygon (if necessary)
                  and fills it in:

                  canvas.polygon([[0, 100], [100, 200], [200, 100]],
                                  fill= 'red ', outline= 'orange ', width=10)



                  19.5 More widgets


                  Tkinter provides two widgets that let users type text: an Entry, which is a single line, and
                  a Text widget, which has multiple lines.

                  en creates a new Entry:
                  entry = g.en(text=  'Default text.  ')
                  The text option allows you to put text into the entry when it is created. The get method
                  returns the contents of the Entry (which may have been changed by the user):
                  >>> entry.get()
                  'Default text.  '
                  te creates a Text widget:

                  text = g.te(width=100, height=5)
                  width and height are the dimensions of the widget in characters and lines.
                  insert puts text into the Text widget:
                  text.insert(END,  'A line of text.  ')
   199   200   201   202   203   204   205   206   207   208   209