Py5Surface.set_visible()

Set the Sketch window’s visiblity.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def draw():
    py5.rect(py5.random(py5.width), py5.random(py5.height), 10, 10)
    py5.println(py5.frame_count)

py5.run_sketch(block=False)
surface = py5.get_surface()

# hide the sketch.
surface.set_visible(False)
# the sketch is no longer visible but there is still output

# after waiting a bit, make the sketch visible again
surface.set_visible(True)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# this sketch will hide itself and reappear elsewhere on your display.

def setup():
    global surface
    global visible
    surface = py5.get_surface()
    visible = True


def draw():
    global visible
    if py5.frame_count % 250 == 0:
        # this negates the visible variable
        visible = not visible
        if visible:
            surface.set_location(py5.random_int(py5.display_width),
                                 py5.random_int(py5.display_height))
        surface.set_visible(visible)

Description

Set the Sketch window’s visiblity. The animation will continue to run but the window will not be visible.

Underlying Java method: PSurface.setVisible

Syntax

set_visible(visible: bool, /) -> None

Parameters

  • visible: bool - desired surface visiblity

Updated on September 11, 2021 16:51:34pm UTC