Files
pybricks-api/examples/ev3/buttons_quickstart/menu.py
T
Laurens Valk b0ffb24a2e examples: import snippets from pybricks-projects
These code samples are rendered in the docs, so we include them here.

For the git history of these snippets, see:
https://github.com/pybricks/pybricks-projects/commits/f4914069aaacfd9ab1e0dd6f05524f62cfc56b29/snippets
2020-11-04 10:17:33 +01:00

31 lines
814 B
Python

def wait_for_button(ev3):
"""
This function shows a picture of the buttons on the EV3 screen.
Then it waits until you press a button.
It returns which button was pressed.
"""
# Show a picture of the buttons on the screen.
ev3.screen.load_image('buttons.png')
# Tip: add text or icons to the image to help you
# remember what each button will do in your program.
# Wait for a single button to be pressed and save the result.
pressed = []
while len(pressed) != 1:
pressed = ev3.buttons.pressed()
button = pressed[0]
# Print which button was pressed
ev3.screen.draw_text(2, 100, button)
# Now wait for the button to be released.
while any(ev3.buttons.pressed()):
pass
# Return which button was pressed.
return button