Advertisement
David90278

Raspberry Pi -Python GUI - Superhero Name Generator

Feb 18th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # guizero - hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox
  3. app = App(title="Create a Hero Name")
  4.  
  5. # Function definitions for your events go here.
  6. def make_hero_name():
  7.     adjective = cmb_adjective.value
  8.     color = txt_color.value
  9.     animal = cmb_animal.value
  10.     hero = adjective + " " + color + " "+ animal
  11.     lbl_output.value = "You are... The " + hero + "."
  12.     if cb_prettify.value == 1:
  13.         lbl_output.text_color = "purple"
  14.     else:
  15.         lbl_output.text_color = "black"
  16.  
  17. # Your GUI widgets go here
  18. message1 = Text(app, text="Choose an adjective")
  19. cmb_adjective = Combo(app, options=["Amazing", "Spectacular", "Incandescent", "Spooktacular", "Redonculus"], selected="Amazing")
  20.  
  21. message2 = Text(app, text="Choose a color")
  22. txt_color = TextBox(app)
  23.  
  24. message3 = Text(app, text="Pick an animal")
  25. cmb_animal = Combo(app, options=["Narwahl", "Jackalope", "Spider Monkey", "Poodle", "Crustacean"], selected="Crustacean")
  26.  
  27. cb_prettify = CheckBox(app, text="Tick the checkbox to make it Pretty!")
  28.  
  29. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
  30. lbl_output = Text(app, text="A hero name will appear here")
  31.  
  32. # Show the GUI on the screen, start listening to events.
  33. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement