Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Text, info
- # this function handles the when_key_pressed event
- def key_press_event(event):
- # check if the <return> key was pressed
- if (event.key == "\r"):
- # you can do anything here - such as get or set values in a widget or call another function
- btn_go_clicked()
- # this function displays an info box with a greeting message
- def btn_go_clicked():
- info("Greetings","Hello, " + txt_name.value + " - I hope you're having a nice day")
- # create a new app
- app = App(title="Display an info box on <return> or button click")
- # set the event handler function for the when_key_pressed event
- app.when_key_pressed = key_press_event
- # define the GUI widgets
- lbl_name = Text(app, text="Hello. What's your name?")
- txt_name = TextBox(app)
- btn_go = PushButton(app, command=btn_go_clicked, text="Done")
- # show the GUI on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement