scipiguy

GUIZero hero 2

Oct 31st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 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, Slider, Picture, ListBox
  3.  
  4. app = App(title="The Super Splendiferous...", height=800, width=700)
  5. app.bg = 'yellow'
  6. app.text_color = "black"
  7. app.font = 'Stencil'
  8. dark_light = 1
  9.  
  10. # Function definitions for my events here
  11. def make_hero_name():
  12.     skin=""
  13.     adjective = bgp_adjective.value
  14.     colour = txt_colour.value
  15.     animal = cmb_animal.value
  16.     generation = sli_gen.value
  17.     birthplace = lstbox_plcbirth.value  
  18.    
  19.     if chk_skin_fur.value == 1:
  20.         skin = skin + "furry "
  21.     if chk_skin_scaly.value == 1:
  22.         skin = skin + "scaly "
  23.     if chk_skin_slip.value == 1:
  24.         skin = skin + "slippery "
  25.    
  26.     hero = adjective + " " + colour + " " + skin + animal + " " + str(generation) + " of " + birthplace
  27.     lbl_output.value = "You are...The " + hero
  28.  
  29. #Pushbutton that sets dark or light mode    
  30. def dark_light_mode():
  31.     global dark_light
  32.     if dark_light == 1:
  33.         dark_light = dark_light * -1
  34.         app.bg = 'black'
  35.         app.text_color = 'yellow'
  36.     else:
  37.         dark_light = dark_light * -1
  38.         app.bg = 'yellow'
  39.         app.text_color = 'black'
  40.    
  41. # My GUI widgets here
  42. btn_make_name = PushButton(app, text=' Dark\Light Mode ', command=dark_light_mode)
  43.  
  44. message1 = Text(app, text="Choose your amazing adjective:")
  45. bgp_adjective = ButtonGroup(app, options=["Happy", "Flappy", "Snappy", "Clappy"], selected="Happy", command=make_hero_name)
  46.  
  47. message2 = Text(app, text="Colour:")
  48. txt_colour = TextBox(app, command=make_hero_name)
  49.  
  50. message3 = Text(app, text="Favourite animal:")
  51. cmb_animal = Combo(app, options=["Anteater", "Bandicote", "Coyote", "Duck", "Eagle", "Frog", "Gerbil", "Hyena", "Iguana", "Jellyfish", "Kakapo", "Llama", "Mole", "Newt"], selected="Anteater", command=make_hero_name)
  52.  
  53. message4 = Text(app, text="Skin Type:")
  54. chk_skin_fur = CheckBox(app, text="Furry ", command=make_hero_name)
  55. chk_skin_scaly = CheckBox(app, text="Scaly ", command=make_hero_name)
  56. chk_skin_slip = CheckBox(app, text="Slippery ", command=make_hero_name)
  57.  
  58. message5 = Text(app, text="Generation:")
  59. sli_gen = Slider(app, start=1, end=3, command=make_hero_name)
  60.  
  61. message6 = Text(app, text="Place of Birth:")
  62. lstbox_plcbirth = ListBox(app, items=["Birmingham","Cambridge", "Cheltenham", "Dundee", "Ely", "London", "Newcastle", "Peterborough", "Potton", "Safron Waldon"], selected="Birmingham", command=make_hero_name)
  63.  
  64. #btn_make_name = PushButton(app, text=' Go! ', command=make_hero_name)
  65. lbl_output = Text(app, text="Hero name being forged...um any moment now...", bg="red", color="yellow")
  66.  
  67. #Make sure the GIF image is in the same folder as this Python file
  68. picture = Picture(app, image='superhero2.gif')
  69.  
  70. # Show the GUI on the screen, start listening to events.
  71. app.display()
Advertisement
Add Comment
Please, Sign In to add comment