Advertisement
AlexParry

Display an info box on <return> or button click in guizero

May 7th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Text, info
  2.  
  3. # this function handles the when_key_pressed event
  4. def key_press_event(event):
  5.     # check if the <return> key was pressed
  6.     if (event.key == "\r"):
  7.         # you can do anything here - such as get or set values in a widget or call another function
  8.         btn_go_clicked()
  9.  
  10. # this function displays an info box with a greeting message
  11. def btn_go_clicked():
  12.     info("Greetings","Hello, " + txt_name.value + " - I hope you're having a nice day")
  13.  
  14. # create a new app
  15. app = App(title="Display an info box on <return> or button click")
  16.  
  17. # set the event handler function for the when_key_pressed event
  18. app.when_key_pressed = key_press_event
  19.  
  20. # define the GUI widgets
  21. lbl_name = Text(app, text="Hello. What's your name?")
  22. txt_name = TextBox(app)
  23. btn_go = PushButton(app, command=btn_go_clicked, text="Done")
  24.  
  25. # show the GUI on the screen
  26. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement