intro to programming - chapter 4 syntax

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

9 Terms

1
New cards

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()).

2
New cards

Creating a Graphics Window

  • win = GraphWin()
    → Opens a default 200×200 pixel window

3
New cards

Creating Points

  • p = Point(x, y)
    → Defines a location in the window.

4
New cards

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.

5
New cards

Customizing Shapes

  • circ.setFill('color')
    → Fills shape with color.

  • circ.setOutline('color')
    → Sets outline color.

6
New cards

Creating Polygons

  • triangle = Polygon(p1, p2, p3)
    → Creates a triangle from three points.

7
New cards

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.

8
New cards

Handling Mouse and Keyboard Input

  • win.getMouse()
    → Waits for a mouse click.

  • win.getKey()
    → Waits for a key press.

9
New cards

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.