Py5Surface.set_location()

Set the Sketch’s window location.

Examples

1
2
3
4
py5.run_sketch(block=False)
surface = py5.get_surface()
# move the sketch window to the upper left corner of the display
surface.set_location(0, 0)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 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’s window location. Calling this repeatedly from the draw() function may result in a sluggish Sketch. Negative or invalid coordinates are ignored. To hide a Sketch window, use Py5Surface.set_visible().

Underlying Java method: PSurface.setLocation

Syntax

set_location(x: int, y: int, /) -> None

Parameters

  • x: int - x-coordinate for window location

  • y: int - y-coordinate for window location

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