5. Computing with Graphics Objects - 5 COMPUTING WITH...

Info icon This preview shows pages 1–9. Sign up to view the full content.

5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Objectives To construct a Graphical User Interface (GUI) window; To construct various shapes, including dots, straight lines, circles, rectangles, triangles and ovals; To combine various shapes to construct complicated graphics; To understand the process of developing a graphical interface; To understand the coordinate system in a GUI window; To construct a bar chart and a line graph; To create interactive graphics using event-driven programming.
Image of page 2
The Object of Objects Basic idea – view a complex system as the interaction of simpler objects. An object is a sort of active data type that combines data and operations. Objects know stuff (contain data) and they can do stuff (have operations). Objects interact by sending each other messages.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Simple Graphics Programming The utilization of objects in Python can be better illustrated using Graphics programming.
Image of page 4
EXERCISE 5.1 Download the graphics.py library from and save it to the following path: C:\<pythron-home-directory>\Lib\site-packages E.g., C:\Python34\Lib\site-packages For MAC: Macintosh HD\Library\Frameworks\Python.framework\Versions\3.4\lib\python3.4\site- packages
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

EXERCISE 5.2 Type the following code in the Shell: >>> import graphics >>> win = graphics.GraphWin()
Image of page 6
Window Creation and Termination This creates a window on the screen. Here the variable “win” represents the window and soon you will add other graphics on it. To close the window, type >>> win.close() We will be working with quite a few commands from the graphics library. Python has an alternative form of import that can help out: >>> from graphics import * >>> win = GraphWin() [Question] How to change the caption and the size of the window?
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

EXERCISE 5.3 Type the following code: >>> p = Point(50, 60) >>> win = GraphWin() >>> p.draw(win)
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '16
  • Rocky Chiang
  • following code

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern