1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Importing the Graphics Library
import graphics
→ Use full module name for each command (e.g., graphics.GraphWin()
).
from graphics import *
→ Use commands directly (e.g., GraphWin()
).
Creating a Graphics Window
win = GraphWin()
→ Opens a default 200×200 pixel window
Creating Points
p = Point(x, y)
→ Defines a location in the window.
Creating and Drawing Shapes
circ = Circle(Point(x, y), radius)
→ Creates a circle with center and radius.
circ.draw(win)
→ Draws the circle in the window.
Customizing Shapes
circ.setFill('color')
→ Fills shape with color.
circ.setOutline('color')
→ Sets outline color.
Creating Polygons
triangle = Polygon(p1, p2, p3)
→ Creates a triangle from three points.
Working with Text
message = Text(Point(x, y), "Your message")
→ Creates a text object.
message.draw(win)
→ Displays the text in the window.
message.setText("New message")
→ Updates the displayed text.
Handling Mouse and Keyboard Input
win.getMouse()
→ Waits for a mouse click.
win.getKey()
→ Waits for a key press.
Using Entry Boxes
inputBox = Entry(Point(x, y), width)
→ Creates a text entry field.
inputBox.draw(win)
→ Displays the entry box.
inputBox.getText()
→ Retrieves user input from the box.