no_loop()#

Stops py5 from continuously executing the code within draw().

Examples#

1def setup():
2    py5.size(200, 200)
3    py5.no_loop()
4
5
6def draw():
7    py5.line(10, 10, 190, 190)
 1x = 0.0
 2
 3
 4def setup():
 5    py5.size(200, 200)
 6
 7
 8def draw():
 9    global x
10    py5.background(204)
11    x = x + 0.1
12    if x > py5.width:
13        x = 0
14    py5.line(x, 0, x, py5.height)
15
16
17def mouse_pressed():
18    py5.no_loop()
19
20
21def mouse_released():
22    py5.loop()
 1some_mode = False
 2
 3
 4def setup():
 5    py5.no_loop()
 6
 7
 8def draw():
 9    if some_mode:
10        # do something
11        pass
12
13
14def mouse_pressed():
15    some_mode = True
16    py5.redraw()  # or call loop()

Description#

Stops py5 from continuously executing the code within draw(). If loop() is called, the code in draw() begins to run continuously again. If using no_loop() in setup(), it should be the last line inside the block.

When no_loop() is used, it’s not possible to manipulate or access the screen inside event handling functions such as mouse_pressed() or key_pressed(). Instead, use those functions to call redraw() or loop(), which will run draw(), which can update the screen properly. This means that when no_loop() has been called, no drawing can happen, and functions like save_frame() or load_pixels() may not be used.

Note that if the Sketch is resized, redraw() will be called to update the Sketch, even after no_loop() has been specified. Otherwise, the Sketch would enter an odd state until loop() was called.

Underlying Processing method: noLoop

Syntax#

no_loop() -> None

Updated on March 22, 2022 21:53:01pm UTC