Cover page images (keyboard)

Introductory Objects and Graphics 1

Wes Griffin & Sue Evans


Adapted from the CS1 Course at Swarthmore College by Lisa Meeden

Hit the space bar for next slide

Learning Outcomes

Procedural Programming

The classic style of computer programming is called procedural programming.

Object-Oriented Programming

There is a more recent style of computer programming called object-oriented programming.

Imagine a program to manage an ATM. Each account the ATM knows about is an object. The account objects hold pieces of data and respond to certain messages.

Creating Objects and Sending Messages

Creating and Closing Windows

More On Windows

The GraphWin constructor takes three parameters: title, width, and height:

>>> GraphWin(<title>, <width>, <height>)

When the parameters are not specified, they have the following default values:

Object Data and Methods

More on Object References

Objects Referencing Other Objects

Drawing Lines

Tic-Tac-Toe Exercise



Changing Coordinate Systems

Tic-Tac-Toe Window

from graphics import *

def main():
    win = GraphWin("Tic-Tac-Toe", 400, 400)

    # set coordinates to go from (0,0) in upper left to (3,3) in lower right
    win.setCoords(0.0, 0.0, 3.0, 3.0)

    # draw vertical lines
    Line(Point(1, 0), Point(1, 3)).draw(win)
    Line(Point(2, 0), Point(2, 3)).draw(win)

    # draw horizontal lines
    Line(Point(0, 1), Point(3, 1)).draw(win)
    Line(Point(0, 2), Point(3, 2)).draw(win)

    # wait for a mouse click before closing window
    win.getMouse()
    win.close()

main()