scipiguy

FutureLearn GUIZero - Superhero Boxes

Nov 3rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 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, Box
  3.  
  4. app = App(title="The Super Splendiferous...", height=950, 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. box1=Box(app, border=2, width=280, height=230)
  45. message1 = Text(box1, text="Choose your amazing adjective:")
  46. bgp_adjective = ButtonGroup(box1, options=["Happy", "Flappy", "Snappy", "Clappy"], selected="Happy", command=make_hero_name)
  47.  
  48. message2 = Text(box1, text="Colour:")
  49. txt_colour = TextBox(box1, command=make_hero_name)
  50.  
  51. message3 = Text(box1, text="Favourite animal:")
  52. cmb_animal = Combo(box1, options=["Anteater", "Bandicote", "Coyote", "Duck", "Eagle", "Frog", "Gerbil", "Hyena", "Iguana", "Jellyfish", "Kakapo", "Llama", "Mole", "Newt"], selected="Anteater", command=make_hero_name)
  53.  
  54. box2=Box(app, border=2, width=280, height=170)
  55. message4 = Text(box2, text="Skin Type:")
  56. chk_skin_fur = CheckBox(box2, text="Furry ", command=make_hero_name)
  57. chk_skin_scaly = CheckBox(box2, text="Scaly ", command=make_hero_name)
  58. chk_skin_slip = CheckBox(box2, text="Slippery ", command=make_hero_name)
  59.  
  60. message5 = Text(box2, text="Generation:")
  61. sli_gen = Slider(box2, start=1, end=3, command=make_hero_name)
  62.  
  63. box3=Box(app, border=2, width=280, height=190)  
  64. message6 = Text(box3, text="Place of Birth:")
  65. lstbox_plcbirth = ListBox(box3, items=["Birmingham","Cambridge", "Cheltenham", "Dundee", "Ely", "London", "Newcastle", "Peterborough", "Potton", "Safron Waldon"], selected="Birmingham", command=make_hero_name)
  66.  
  67. #btn_make_name = PushButton(app, text=' Go! ', command=make_hero_name)
  68. lbl_output = Text(app, text="Hero name being forged...um any moment now...", bg="red", color="yellow")
  69.  
  70. #Make sure the GIF image is in the same folder as this Python file
  71. picture = Picture(app, image='superhero.gif')
  72.  
  73. # Show the GUI on the screen, start listening to events.
  74. app.display()
Add Comment
Please, Sign In to add comment