Programs and Activities

Become familiar with the graphics library

1. Draw a Circle

#! /usr/bin/python3 # =================================================================== # print a circle at the center of the window # =================================================================== import graphics as gr win_height = 801 win_width = 801 # ---- create a window win = gr.GraphWin("Draw Circle", win_width, win_height) win.setBackground("white") # ---- draw a circle c = gr.Circle(gr.Point(win_width/2,win_height/2), 100) c.draw(win) # ---- end program win.getMouse() # wait for click in windows win.close() # close window

1.2. Fill in Circle

1.3. Draw a line

Draw a spiral

1.4. Draw a rectangle

1.5. Draw an oval

1.6. Draw an polygon

1.7. Mouse Input

1.7.1. When the mouse is clicked in the window, draw a circle at that location. Erase the circle at the old location, if any.

1.8. Key Input

1.8.1. Draw a circle or other graphics object in the window. Use the arrow keys to move it around in the window. Use the "q" or "Q" key to exit the program.

1.9. Draw text

in 1.7.1. and/or 1.8.1. display the coordinates of the mouse click in the window.