Think Python How to Think Like a Computer Scientist
Chapter 19. Case study: Tkinter
Download 1.04 Mb. Pdf ko'rish
|
thinkpython
186
Chapter 19. Case study: Tkinter 19.4 Coordinate sequences The rectangle method takes a sequence of coordinates that specify opposite corners of the rectan- gle. This example draws a green 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 example 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.') END is a special index that indicates the last character in the Text widget. You can also specify a character using a dotted index, like 1.1, which has the line number before the dot and the column number after. The following example adds the letters 'nother' after the first character of the first line. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling