Turn to page 129 of your text and try the commands that are
given in
that session. You will need to import the graphics module with
from graphics import *
Your window should look like page 130 when you are
done. Then execute
win.close()
Here are some more things to try with a new window.
Note that in the last part there are loops within loops.
>>>
win = GraphWin("First Try")
>>>
win.setBackground("yellow")
>>>
>>>
line1 = Line(Point(20,190),Point(190,190))
>>>
line1.draw(win)
>>>
line1.setWidth(10)
>>>
>>>
line1.move(0,-10)
>>>
c1 = Circle(Point(100,100),20)
>>>
c1.setFill("green")
>>>
c1.draw(win)
>>>
import time
>>>t1
= Text(Point(100,30), "Move Ball!")
>>>
t1.draw(win)
>>>for
x in range(10):
for i in range(12):
c1.move(0,5)
time.sleep(.1)
for i in range(12):
c1.move(0,-5)
time.sleep(.1)
>>>win.close()
Experiment with the various graphics objects. Try as many methods as you can. If you like, you can try making a scene., and elaborate it for Program 3.
Put your code (at least eventually) in a file so the whole scene is drawn automatically. Be sure to have a line at the end to close your window. Then when you run the program, do NOT close the graphics window with the close button (the X) in the corner of the window. Always have your program handle it. One issue with the simple graphics package is that it is alway looking for program actions in a specified sequence, so it can get messed up if you use this independent way of closing the window.
Show your creative work to a TA.