Utilities
scripton.wait
def wait(timeout: int | float = 0) -> KeyboardEvent | None:
...
Calling the scripton.wait
function causes the script to pause execution until the user presses a key in the IDE.
An optional timeout
argument may be provided. The timeout is in seconds and may be fractional (e.g.: 0.5
for 500 milliseconds).
It returns information about the pressed key (as a KeyboardEvent instance). If the timeout was hit, it returns None
.
Example 1
from scripton import wait, show
dataset = ...
for datum in dataset:
show(datum['input_image'], key='input_image')
show(datum['segmentation'], key='segmentation')
wait()
Example 2
Taking an action based on the pressed key.
from scripton import wait
counter = 0
while True:
match wait().key:
case 'ArrowUp':
counter += 1
case 'ArrowDown':
counter -= 1
case 'Escape':
break
print(f'Counter: {counter}')