ling 408/508: programming for linguistssandiway/ling508-15/...last time • library graphics.py –...

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

Upload: others

Post on 19-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

LING408/508:ProgrammingforLinguists

Lecture23

November25th

Page 2: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

LastTime

•  Librarygraphics.py– builtontopofTkinter(PythoninterfacetoTk)– builtontopofTk(graphicslibrary)– builtontopofX11(graphicslibrary)onUbuntu

Page 3: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.py

Page 4: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.py•  Objectinheritance(seegraphics.pycode):•  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 Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

Directlyinwishtcl/tk !

Stylis'cvaria'on…graphics.py:useprimiWveobjectPoint!tk:usesplainx,ycoordinates

Page 6: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

•  textbook5.7:– p = win.getMouse() returnsaPoint

Page 7: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

Page 8: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

Page 9: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

•  textbook5.7:– input = Entry(center,width)

createsauser-editabletextbox

Page 10: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

Page 11: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

InteracWveGraphics

Page 12: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 13: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 14: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 15: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI•  Color:

•  Colornames:– seehZp://wiki.tcl.tk/37701

Page 16: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 17: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 18: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 19: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 20: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

graphics.pyAPI

Page 21: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

SecWon6.2-6.4

•  Happybirthdayexample

•  nestedfuncWoncalls:

Note:parametersarepassedbyvalue(copying)-  notbyreference(pointer)-  (someotherprogramminglanguagesallowbothopWons)

Page 22: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

SecWon6.5

•  Tosendavalueback,use–  return<Expression>

•  MulWplevaluescanbereturned:

Note:Noneisreturnedwhenthereisnoreturnstatement

Page 23: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

triangle2.py•  Calculatestheperimeterofatriangleyoudraw.

Page 24: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

triangle2.py !

Note:parametersarepassedbyvalue(copying)-  mutableobjects(Point)

Page 25: LING 408/508: Programming for Linguistssandiway/ling508-15/...Last Time • Library graphics.py – built on top of Tkinter (Python interface to Tk) – built on top of Tk (graphics

triangle2.py !