ling 408/508: programming for linguists lecture 23 november 25 th
DESCRIPTION
graphics.pyTRANSCRIPT
![Page 1: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/1.jpg)
LING 408/508: Programming for Linguists
Lecture 23November 25th
![Page 2: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/2.jpg)
Last Time
• Library graphics.py– built on top of Tkinter (Python interface to Tk)– built on top of Tk (graphics library)– built on top of X11 (graphics library) on Ubuntu
![Page 3: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/3.jpg)
graphics.py
![Page 4: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/4.jpg)
graphics.py• Object inheritance (see graphics.py code):• GraphicsObject– Point: draw, move, clone– Text: clone, move, draw, setText, getText, setFace– Polygon: clone, getPoints, move, draw– _Bbox: move• Rectangle: draw• Oval: clone, draw–Circle: clone, getRadius
• Line: clone, draw, setArrow
![Page 5: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/5.jpg)
Directly in wish tcl/tk
Stylistic variation…graphics.py: use primitive object Pointtk: uses plain x,y coordinates
![Page 6: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/6.jpg)
Interactive Graphics
• textbook 5.7:– p = win.getMouse() returns a Point
![Page 7: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/7.jpg)
Interactive Graphics
![Page 8: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/8.jpg)
Interactive Graphics
![Page 9: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/9.jpg)
Interactive Graphics
• textbook 5.7:– input = Entry(center,width) creates a user-
editable text box
![Page 10: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/10.jpg)
Interactive Graphics
![Page 11: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/11.jpg)
Interactive Graphics
![Page 12: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/12.jpg)
graphics.py API
![Page 13: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/13.jpg)
graphics.py API
![Page 14: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/14.jpg)
graphics.py API
![Page 15: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/15.jpg)
graphics.py API
• Color:
• Color names: – see http://wiki.tcl.tk/37701
![Page 16: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/16.jpg)
graphics.py API
![Page 17: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/17.jpg)
graphics.py API
![Page 18: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/18.jpg)
graphics.py API
![Page 19: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/19.jpg)
graphics.py API
![Page 20: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/20.jpg)
graphics.py API
![Page 21: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/21.jpg)
Section 6.2-6.4
• Happy birthday example
• nested function calls:
Note: parameters are passed byvalue (copying)- not by reference (pointer)- (some other programming languages allow both options)
![Page 22: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/22.jpg)
Section 6.5
• To send a value back, use – return <Expression>
• Multiple values can be returned:
Note: None is returned when there is no return statement
![Page 23: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/23.jpg)
triangle2.py• Calculates the perimeter of a triangle you draw.
![Page 24: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/24.jpg)
triangle2.py
Note: parameters are passed byvalue (copying)- mutable objects (Point)
![Page 25: LING 408/508: Programming for Linguists Lecture 23 November 25 th](https://reader035.vdocuments.mx/reader035/viewer/2022062401/5a4d1af47f8b9ab059980100/html5/thumbnails/25.jpg)
triangle2.py