scipiguy

Future Learn GUIZero Superhero

Oct 30th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. # A GUIZero - The Super Splendiferous Superhero name generator (based on FutureLearn Course RPi Foundation)
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox
  3. app = App(title="The Super Splendiferous...", height=400, width=600)
  4. app.bg = 'yellow'
  5. app.font = 'Stencil'
  6.  
  7. # Function definitions for your events go here.
  8. def make_hero_name():
  9.     skin=""
  10.     adjective = bgp_adjective.value
  11.     colour = txt_colour.value
  12.     animal = cmb_animal.value
  13.    
  14.     print(chk_skin_fur.value)
  15.     if chk_skin_fur.value == 1:
  16.         skin = skin + "furry "
  17.     if chk_skin_scaly.value == 1:
  18.         skin = skin + "scaly "
  19.     if chk_skin_slip.value == 1:
  20.         skin = skin + "slippery "
  21.    
  22.     hero = adjective + " " + colour + " " + skin + animal
  23.     lbl_output.value = "You are...The " + hero
  24.  
  25. # Your GUI widgets go here
  26. message1 = Text(app, text="Choose your amazing adjective:")
  27. bgp_adjective = ButtonGroup(app, options=["Happy", "Flappy", "Snappy", "Clappy"], selected="Happy")
  28.  
  29. message2 = Text(app, text="Colour:")
  30. txt_colour = TextBox(app)
  31.  
  32. message3 = Text(app, text="Favourite animal:")
  33. cmb_animal = Combo(app, options=["Anteater", "Bandicote", "Coyote", "Duck", "Eagle", "Frog", "Gerbil", "Hyena", "Iguana", "Jellyfish", "Kakapo", "Llama", "Mole", "Newt"], selected="Anteater")
  34.  
  35. message4 = Text(app, text="Skin Type:")
  36. chk_skin_fur = CheckBox(app, text="Furry ", command=make_hero_name)
  37. chk_skin_scaly = CheckBox(app, text="Scaly ", command=make_hero_name)
  38. chk_skin_slip = CheckBox(app, text="Slippery ", command=make_hero_name)
  39.  
  40. btn_make_name = PushButton(app, text=' Go! ', command=make_hero_name)
  41. lbl_output = Text(app, text="Hero name being forged...um any moment now...", bg="red", color="yellow")
  42.  
  43. # Show the GUI on the screen, start listening to events.
  44. app.display()
Add Comment
Please, Sign In to add comment