Screen
The Screen is the base object for any pyDraw program, and can perform a variety of different tasks.
Quick Reference can help with simple issues or give you a basic understanding of the methods available, but it can never replace full documentation which is available here.

Initialization

You can initialize a Screen by passing a width and height (in pixels), and you can also pass an optional title. The default title is: "pydraw".
1
screen = Screen(800, 600)
2
screen = Screen(800, 600, 'Title')
Copied!

Title

The title may be set in the constructor, but can also be modified later with:
1
screen.title(title)
Copied!

Size

The Screen maintains its width and height and is not resizable. The values are retrievable via:
1
screen.width()
2
screen.height()
Copied!
Also, you can resize the Screen manually with:
1
screen.resize(width, height)
Copied!

Color

The Screen's background is white by default, but it can be modified (or retrieved) with:
1
screen.color() # Retrieve the current Color
2
screen.color(color) # Set a new Color
Copied!
Note: Colors in pyDraw are wrapped with the Color class.

Background Image

You can also set the background image of the screen with:
1
screen.picture(image_file)
Copied!

Input

You can have the screen listen for input by calling this after defining input methods:
1
screen.listen()
Copied!

Example

1
def mousedown(button, location):
2
# input handling code
3
4
screen.listen() # Register any input methods
Copied!

Text Input (Prompt)

You can initiate a prompt to collect user input simply:
1
screen.prompt(text) # Ask a question
2
screen.prompt(text, title) # Specify a title for the dialog
Copied!

Mouse Location

You can retrieve the mouses current (or last known) location like so:
1
screen.mouse()
Copied!

Screen Capture

It is possible to capture the contents of the Screen and write it to a specified image file:
1
screen.grab() # Just get an image and give it a random name
2
screen.grab(filename) # Specify a filename to save to
Copied!

Updating and Clearing

You can update/clear the screen as expected:
1
screen.update() # Update the screen to display new changes
2
screen.clear() # Clear all objects off the Screen
Copied!

Sleeping and Delay

The Screen has the ability to delay the program by a specified amount in seconds, but will also calculate a deltaTime in order to keep program execution delays as consistent as possible:
1
screen.sleep(seconds)
Copied!
This method can only be used while within a while loop, if you want to normally delay a program, you should call:
1
import time
2
time.sleep(seconds)
Copied!

Removing Objects

Although a method exists on all objects to remove themselves, the Screen is also able to remove objects from itself:
1
screen.remove(obj)
Copied!

Objects List

You can retrieve a list of all active objects (not including grid and helpers):
1
screen.objects() # Returns a tuple (immutable list) of all objects.
Copied!

Grids and Helpers

Screens have a fairly advanced grid system, allowing you to specify the number of rows or columns, or optionally the size of each cell (the default size of the cells will be 50x50):
1
screen.grid(rows, cols) # Specify # of rows and cols
2
screen.grid(cellsize=(50, 50)) # Specify the cellsize
3
4
screen.toggle_grid(state) # Toggle the grid's visibility
Copied!
You can also activate helper-labels for coordinates like so (every 100 pixels):
1
screen.grid(rows, cols, helpers=True) # Label coordinates
Copied!
Be careful when creating or destroying grids, as it is a somewhat intensive process.
Last modified 7mo ago