You are welcome to look over the code in graphics.py
,
but do not worry about the details of the implementation. More
information about the library can be found here.
For methods involving color, you can look here
for color options. In your code, you will (minimally) make use of the
following methods from this module:
Graphics Function or Method | Behavior |
---|---|
GraphWin(title, width, height) |
Constructs a new graphics window (or GraphWin) for drawing on the
screen. The parameters are optional; the default title is “Graphics
Window,” and the default size is 200 x 200 pixels. Example: win = GraphWin("Boggle", 400, 400) |
getMouse() |
Pauses (or blocks) and waits for the user to click their mouse in
the window and returns where the mouse was clicked as a
Point object (a tuple, with x and
y values). Example: click_point = win.getMouse() |
Point(x, y) |
Constructs a Point having the given coordinates. Example: a_point = Point(3.5, 8) |
pt.getX() and pt.getY() |
Returns the x and y coordinate of a Point, respectively. Example: x_val = a_point.getX() and
y_val = a_point.getY() |
Rectangle(point1, point2, fillcolor) |
Constructs a Rectangle having opposite corners at point1 (top left)
and point2 (bototm right). Example: aRect = Rectangle(Point(1, 3), Point(4, 7), "white") |
rect.setFillColor(color) |
Sets the fill color of the Rectangle to color (a
string). Example: a_rect.setFillColor("pink") |
rect.getFillColor() |
Gets the fill color of the Rectangle (as a string). Example: var = a_rect.getFillColor() |
Text(anchor_point, text_string) |
Constructs a Text object that displays text_string
centered at anchor_point . The text is displayed
horizontally.Example: message = Text(Point(3,4), "Hello!") |
txt.setText(string) |
Sets the text of the Text object to string .Example: message.setText("Goodbye!") |
txt.getText() |
Gets the text of the Text object (as a string). Example: var = message.getText() |
txt.setTextColor(color) |
Sets the color of the Text to color (a string). Note:
setFill(color) has the same effect on Text objects.Example: message.setTextColor("pink") |
txt.getTextColor() |
Gets the color of the Text (as a string). Note:
setFill(color) has the same effect on Text objects.Example: var = message.getTextColor() |
TextRect(rect, text) |
Constructs a TextRect (a Rectangle and a
Text instance grouped together into one object) |
textrect.setFillColor(color) |
Sets the fill color of the TextRect to color (a
string).Example: textrect.setFillColor("pink") |
textrect.getFillColor(color) |
Gets the fill color of the TextRect (as a string). Example: var = textrect.getFillColor() |
textrect.getText() |
Gets the text of the TextRect’s Text object (as a string). Example: var = textrect.getText() |
textrect.setTextColor(color) |
Sets the color of the TextRect’s Text to color (a
string). Example: textrect.setTextColor("pink") |
Feel free to check out the documentation for other methods that you may find helpful as you customize your implementation.
The graphics package was originally copied from here.