Advertisement
fnogal

SuperHeroName

Dec 6th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. # -------------------------------------------------------------------
  2. # Programming with GUIs Raspberry Pi Foundation
  3. # Section 1.9
  4. # The Super Hero Name Generator
  5. # -------------------------------------------------------------------
  6.  
  7. from guizero import App, ButtonGroup, CheckBox, Combo, ListBox, Picture, PushButton, Text, TextBox
  8.  
  9. # Function definitions for your events go here.
  10. def make_hero_name():
  11. adjective = bgp_adjective.value
  12. adj2 = lbox_adjective.value
  13. colour = txt_colour.value
  14. animal = cmb_animal.value
  15. hero = adjective + " " + adj2 + " " + colour + " " + animal
  16. lbl_output.value = "You are... The " + hero + "."
  17.  
  18. def toggle_background():
  19. if bgrd_select.value == 1 :
  20. bgcolor = "black"
  21. fgcolor = "white"
  22. bgrd_select.text = "White background"
  23. else :
  24. bgcolor = "white"
  25. fgcolor = "black"
  26. bgrd_select.text = "Dark background"
  27.  
  28. app.bg = bgcolor
  29. message1.text_color = fgcolor
  30. message1a.text_color = fgcolor
  31. message1b.text_color = fgcolor
  32. message2.text_color = fgcolor
  33. txt_colour.text_color = fgcolor
  34. message3.text_color = fgcolor
  35. bgp_adjective.text_color = fgcolor
  36. lbox_adjective.text_color = fgcolor
  37. cmb_animal.text_color = fgcolor
  38. lbl_output.text_color = fgcolor
  39. btn_make_name.text_color = fgcolor
  40. bgrd_select.text_color = fgcolor
  41.  
  42. app = App(title="Super Hero Name Generator",
  43. width=400,
  44. height=600)
  45.  
  46. # GUI widgets go here
  47. picture = Picture(app, image="images/alien.png")
  48. message1 = Text(app, text="To find the perfect name for your super hero",
  49. align="left")
  50. message1a = Text(app, text="select the best fit from",
  51. align="left")
  52. bgp_adjective = Combo(app,
  53. options=["Awkward", "Bright", "Clueless", "Disgraceful", "Emotional", "Facetious", "Gigantic",
  54. "Inocent", "Maverick", "Spooky", "Wicked"],
  55. selected="Inocent",
  56. align="left")
  57. message1b = Text(app, text="and also from",
  58. align="left")
  59. lbox_adjective = ListBox(app,
  60. items=["Cheerful", "Geeky", "Mindless", "Obnoxious", "Willful"],
  61. align="left")
  62.  
  63. message2 = Text(app, text="Pick a colour for the uniform")
  64. txt_colour = TextBox(app,text="Invisible")
  65.  
  66. message3 = Text(app, text="What animal more closely resembles the hero?")
  67. cmb_animal = Combo(app,
  68. options=["Ant", "Beetle", "Cat", "Dolphin", "Gazele", "Hipo","Sloth", "Velociraptor", "Whale"],
  69. selected="Ant")
  70. cmb_animal.width=20
  71.  
  72. lbl_output = Text(app, text="A hero name will appear here")
  73. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name, grid=[100,20])
  74.  
  75. bgrd_select = CheckBox(app, text="Dark background",command=toggle_background)
  76. # Set up event triggers here
  77.  
  78.  
  79. # Show the GUI on the screen, start listening to events.
  80.  
  81.  
  82. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement