Run the Sketch.
py5.run_sketch(block=True) print("this message will not be printed until after the sketch exits")
py5.run_sketch(block=False) print("this message will be printed immediately, while the sketch is running")
# run the sketch with the window at position 400, 300 on display #1 py5.run_sketch(block=False, py5_options=['--location=400,300', '--display=1'], sketch_args=['py5 is awesome']) # this will print 'py5 is awesome' print(py5.pargs)
Run the Sketch. Code in the
draw() functions will be used to actualize your Sketch.
block parameter to specify if the call to
run_sketch() should return immediately (asynchronous Sketch execution) or block until the Sketch exits. If the
block parameter is not specified, py5 will first attempt to determine if the Sketch is running in a Jupyter Notebook or an IPython shell. If it is,
block will default to
Blocking is not supported on OSX. This is because of the (current) limitations of py5 on OSX. If the
block parameter is set to
True, a warning message will appear and it will be changed to
A list of strings passed to
py5_options will be passed to the Processing PApplet class as arguments to specify characteristics such as the window’s location on the screen. A list of strings passed to
sketch_args will be available to a running Sketch using pargs. See the third example for an example of how this can be used.
run_sketch() in module mode, py5 will by default search for functions such as
draw(), etc. in the caller’s stack frame and use those in the Sketch. If for some reason that is not what you want or does not work because you are hacking py5 to do something unusual, you can use the
sketch_functions parameter to pass a dictionary of the desired callable functions. The
sketch_functions parameter is not available when coding py5 in class mode. Don’t forget you can always replace the
draw() function in a running Sketch using hot_reload_draw().
When programming in module mode and imported mode, py5 will inspect the
setup() function and will attempt to split it into synthetic
setup() functions if both were not created by the user and the real
setup() function contains calls to size(), full_screen(), smooth(), no_smooth(), or pixel_density(). Calls to those functions must be at the very beginning of
setup(), before any other Python code (except for comments). This feature allows the user to omit the
settings() function, much like what can be done while programming in the Processing IDE. This feature is not available when programming in class mode.
When running a Sketch asynchronously through Jupyter Notebook, any
run_sketch() call. This will continue to be true if the user moves on to execute code in other Notebook cells. Use set_println_stream() to customize this behavior. All py5 error messages and stack traces are routed through the println() method. Be aware that some error messages and warnings generated inside the Processing Jars cannot be controlled in the same way, and may appear in the output of the active cell or mixed in with the Jupyter Kernel logs.
run_sketch( block: bool = None, # method returns immediately (False) or blocks until Sketch exits (True) *, py5_options: list[str] = None, # command line arguments to pass to Processing as arguments sketch_args: list[str] = None, # command line arguments that become Sketch arguments sketch_functions: dict[str, Callable] = None # sketch methods when using module mode ) -> None
Updated on September 01, 2022 16:36:02pm UTC