Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Text
- # this function handles the when_key_pressed event
- def key_press_event(event):
- # display a message which includes the key a user just pressed
- text.value = "You pressed the {} key".format(event.key)
- # check if the <return> key was pressed
- if (event.key == "\r"):
- text.value = "The Enter key was pressed"
- # create a new app
- app = App(title="Key Press Example")
- # set the event handler function for the when_key_pressed event
- app.when_key_pressed = key_press_event
- # create a text widget and give it a default value
- text = Text(app)
- text.value = "Press a key"
Add Comment
Please, Sign In to add comment