Advertisement
brendan-stanford

superhero-2.0

Sep 30th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #import libraries
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, ListBox, Picture
  3. app = App(title="My-Hero", width=700, height=600)
  4.  
  5. #Name generator function
  6. def make_hero():
  7. start_adjectives = cmb_adj1.value
  8. colour = cmb_clr.value
  9. animal = cmb_aml.value
  10. end_adjective = cmb_adj2.value
  11. planet = txt_planet.value
  12. hero = start_adjectives + " " + colour + " " + animal + " " + end_adjective + " from the planet " + planet
  13. lbl_output.value = "You are... the " + hero + "!"
  14.  
  15. #dark mode function
  16. def dark_mode():
  17. app.bg = "black"
  18. txt_adj1.text_color = "white"
  19. cmb_adj1.text_color = "white"
  20. txt_clr.text_color = "white"
  21. cmb_clr.text_color = "white"
  22. txt_aml.text_color = "white"
  23. cmb_aml.text_color = "white"
  24. txt_adj2.text_color = "white"
  25. cmb_adj2.text_color = "white"
  26. txt_pt.text_color = "white"
  27. txt_planet.text_color = "white"
  28. txt_drk.text_color = "white"
  29. chk_drk.text_color = "white"
  30. btn_name.text_color = "white"
  31. lbl_output.text_color = "white"
  32.  
  33. #GUI widgets
  34. pic = Picture(app, image = "/home/pi/Desktop/super-dog.png", height=50, width=200)
  35.  
  36. txt_adj1 = Text(app, text="Select your start adjectives")
  37. cmb_adj1 = Combo(app, options = ["Amazing", "Malicious", "Brave", "Stupendous", "Zany"], selected = "Amazing", width=20)
  38.  
  39. txt_clr = Text(app, text = "Choose your colour")
  40. cmb_clr = Combo(app, options = ["Red", "Blue", "Yellow"], selected = "Red", width=20)
  41.  
  42. txt_aml = Text(app, text = "Choose your animal")
  43. cmb_aml = Combo(app, options = ["Aardvark", "Bear", "Deer", "Dog", "Owl", "Turtle", "Zebra"], selected = "Aardvark", width = 20)
  44.  
  45. txt_adj2 = Text(app, text="Select your end adjective")
  46. cmb_adj2 = Combo(app, options = [" of doom", " of power", "of terror", " of awesome"], selected = " of doom", width=20)
  47.  
  48. txt_pt = Text(app, text = "Enter your home planet")
  49. txt_planet = TextBox(app)
  50.  
  51. txt_drk = Text(app, text = "Enable dark mode?")
  52. chk_drk = CheckBox(app, text = "Turn on dark mode!", command = dark_mode)
  53.  
  54. btn_name = PushButton(app, text="Make my Hero", command = make_hero)
  55. lbl_output = Text(app, text="A hero will appear here")
  56.  
  57. #Show GUI; wait for events
  58. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement