Contents

  1. graphics_test.py
  2. rectangle.py

graphics_test.py 1/2

[
top][prev][next]
# Graphics Test Script
# by Sara Sprenkle

from graphics import *

win = GraphWin("My Circle", 200, 200)
point = Point(100,100)
c = Circle(point, 10)
c.draw(win)

c.setOutline(color_rgb(200, 0, 0))

# demonstrate what happens, outside of IDLE, if the line below is commented out.
win.getMouse()

rectangle.py 2/2

[
top][prev][next]
# Draw a rectangle using the graphics API
# by CSCI111

from graphics import *

win = GraphWin("Our Rectangle")

upperLeftPoint = Point(50, 50)
lowerRightPoint = Point(100, 100)
rectangle = Rectangle(upperLeftPoint, lowerRightPoint)
# Alternative, not recommended approach: 
# r = Rectangle( Point(50, 50), Point(100, 100) )

# draw the rectangle, then wait for user to click the mouse
rectangle.draw(win)
win.getMouse()

# move the rectangle to the right 10 px
rectangle.move(10,0)

# get and display the rectangle's new coordinates
newUpperLeftPoint = rectangle.getP1()
newLowerRightPoint = rectangle.getP2()

print("coordinate of upper left point:", newUpperLeftPoint)
print("coordinate of lower right point:", newLowerRightPoint)

# How would I get just the X coordinate of the upper left point?

# pause, waiting for the user to click
win.getMouse()


Generated by GNU Enscript 1.6.6.