Screen
Create and control the pyDraw canvas, drawing loop, input, and dialogs.
- class pydraw.screen.Screen(width: int = 800, height: int = 600, title: str = 'pydraw')
Bases:
objectA class containing methods and values that can be manipulated in order to affect the window that is created. Sort of like a canvas.
- class Key(key: str)
Bases:
object- key() str
Returns the string for the key.
- Returns:
the key in ascii
- add(obj) None
Add an object back to the Screen after having removed it (with Object.remove() or Screen.remove(object)
- Parameters:
obj – the Object to add back.
- Returns:
None
- alert(text: str, title: str = 'Alert', accept_text: str = 'Ok', cancel_text: str = 'Cancel') bool
Displays a dialog-box alert, and returns
- Parameters:
text – The text to display in the body of the dialog
title – The title of the dialog-box
accept_text – The text displayed on the accept button, defaults to ‘Ok’
cancel_text – The text displayed on the cancel button, defaults to ‘Cancel’
- Returns:
True if accept was pressed, False if cancel was pressed
- clear() None
Clears the screen.
- Returns:
None
- color(color: Color = None) Color
Set the background color of the screen.
- Parameters:
color – the color to set the background to
- Returns:
None
- contains(obj) bool
Returns whether or not the passed object exists on the Screen (is in the objects cache)
- Parameters:
obj – the Object to check
- Returns:
a boolean
- exit() None
Called at the end of pydraw programs as an event for successful program execution and termination. To keep a program open, use Screen.loop().
- Returns:
None
- fullscreen(fullscreen: bool = None) bool
Get or set the fullscreen state of the application. Note that this will not resize your shapes, nor will it REPOSITION them. It is highly recommended that you call this method before creating any shapes!
!!! EXPERIMENTAL !!!
- Parameters:
fullscreen – the new fullscreen state, if any
- Returns:
the current fullscreen state of the Screen
- grab(filename: str = None) str
Grabs a screenshot of the image and saves it to the directory with the specified filename! Note that if no filename is specified the file will be given a name based on the epoch time.
- Parameters:
filename – the name of the file to save the screenshot to.
- Returns:
the name of the file.
- grid(rows: int = None, cols: int = None, cellsize: tuple = (50, 50), helpers: bool = True)
- gridlines() tuple
Allows you to retrieve the lines of the grid, but note that you cannot modify them!
- Returns:
a tuple (immutable list) of the gridlines.
- height() int
Returns the height of the CANVAS within the screen. Important.
- Returns:
- listen() None
Reads the file for input functions and registers them as callbacks! The input-type is determined by the name of the function.
- Allowed Names:
mousedown
mouseup
mousedrag
keydown
keyup
keypress (deprecated)
- Returns:
None
- loop() None
Holds the program open and calls screen.update() for you. Must be used at the end of any pyDraw program unless there is a while loop with screen.update() in it instead.
- Returns:
None
- mouse() Location
Get the current mouse-position
- Returns:
the mouse-position in the form of a Location
- objects() tuple
Retrieves all objects on the Screen!
- Returns:
A tuple (immutable list) of Objects (you will want to check types for certain methods!)
- picture(pic: str) None
Set the background picture of the screen.
- Parameters:
pic – the path to said picture from the file
- Returns:
None
- prompt(text: str, title: str = 'Prompt') str
Prompts the user for keyboard input
- Param:
text the text to prompt the user with
- Param:
title the title of the dialog box
- Returns:
None
- remove(obj)
- reset() None
Resets the screen, removing all objects and input methods.
- Returns:
None
- resize(width: int, height: int) None
@deprecated (does not work on all OSes)
Resize the screen to new dimensions
- Parameters:
width – the width to resize to
height – the height to resize to
- Returns:
None
- scene(scene=None)
Apply a new scene to the screen!
Note that this will override ALL previously registered input handlers.
- Parameters:
scene – The Scene to apply!
- Returns:
the new scene that was set, the existing scene if no args passed, or None
- size() -> (<class 'int'>, <class 'int'>)
Get the size of the WINDOW (please note this is not the canvas, and those attributes should be retrieved using the width() and height() methods respectively)
- Returns:
a tuple containing the width and height of the WINDOW
- sleep(delay: float, delta: bool = False) float | None
Pause execution, optionally compensating for work done during the frame.
With
delta=False, this sleeps for the full delay and returns None. Withdelta=True, it sleeps only until the next frame deadline and returns the actual duration of the completed frame in seconds. The returned value is intended to be used asdtin the next frame.The first delta-enabled call returns the requested delay because there is no previous frame timestamp to measure. If execution falls more than one frame behind, the deadline is reset so the loop does not run a burst of catch-up frames.
- Parameters:
delay – target frame duration in seconds
delta – whether to enable compensated frame pacing and return dt
- Returns:
None normally, or the completed frame duration when delta=True
- stop() None
Deprecated. Use screen.loop instead.
- Returns:
None
- title(title: str = None) str
Get or set the title of the screen.
- Parameters:
title – the title to set to, if any
- Returns:
the title
- toggle_grid(value=None)
- update() None
Updates the screen.
- Returns:
None
- width() int
Returns the width of the CANVAS within the screen. Important.
- Returns:
an integer representing the width of the canvas