Top Banner
LING 408/508: Programming for Linguists Lecture 23 November 25 th
25

LING 408/508: Programming for Linguists Lecture 23 November 25 th.

Jan 08, 2018

Download

Documents

Mervin Bennett

graphics.py
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

LING 408/508: Programming for Linguists

Lecture 23November 25th

Page 2: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

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.

graphics.py

Page 4: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

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.

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.

Interactive Graphics

• textbook 5.7:– p = win.getMouse() returns a Point

Page 7: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

Interactive Graphics

Page 8: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

Interactive Graphics

Page 9: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

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.

Interactive Graphics

Page 11: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

Interactive Graphics

Page 12: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 13: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 14: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 15: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

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.

graphics.py API

Page 17: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 18: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 19: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 20: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

graphics.py API

Page 21: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

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.

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.

triangle2.py• Calculates the perimeter of a triangle you draw.

Page 24: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

triangle2.py

Note: parameters are passed byvalue (copying)- mutable objects (Point)

Page 25: LING 408/508: Programming for Linguists Lecture 23 November 25 th.

triangle2.py