12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

19.6. Packing widgets 185>>> text.insert(1.1, 'nother')The get method reads the text in the widget; it takes a start and end index as arguments. Thefollowing example returns all thetext inthewidget, including thenewline character:>>> text.get(0.0, END)'Another line of text.\n'The delete method removes text from the widget; the following example deletes all but the firsttwocharacters:>>> text.delete(1.2, END)>>> text.get(0.0, END)'An\n'Exercise 19.3 Modify your solution to Exercise 19.2 by adding an Entry widget and a second button.When the user presses the second button, it should read a color name from the Entry and use itto change the fill color of the circle. Use config to modify the existing circle; don’t create a newone.Your program should handle the case where the user tries to change the color of a circle that hasn’tbeen created, and the casewhere the color name isinvalid.You can see mysolutionatthinkpython.com/code/circle_demo.py.19.6 PackingwidgetsSo far we have been stacking widgets in a single column, but in most GUIs the layout is morecomplicated. For example, hereisaslightlysimplified version of TurtleWorld (seeChapter 4).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!