Advertisement
Buzzbow

superhero challenge

Aug 17th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # guizero - Hero challenge generator
  2. from guizero import App, Text, ButtonGroup, Combo, ListBox, PushButton, TextBox, CheckBox, Slider, Picture
  3. app = App(title="Hero-challenge", bg = "grey", height = 900, width =380 )
  4.  
  5.  
  6. # Function definitions
  7.  
  8. def slider_changed(slider_value):
  9. sl_amount.value = slider_value
  10.  
  11.  
  12. def change_color(value):
  13. lb_colour.text_color = value
  14.  
  15.  
  16. def make_hero_name():
  17. adjective = cmb_adjective.value
  18. colour = lb_colour.value
  19. animal = cmb_animal.value
  20. slider = sl_amount.value
  21. superhero = bgp_superhero.value
  22. if cb_speedy.value == 1:
  23. speedy = ", Speedy"
  24. else:
  25. speedy = ""
  26. if cb_agile.value == 1:
  27. agile = ", Agile"
  28. else:
  29. agile= ""
  30. if cb_can_fly.value == 1:
  31. can_fly = ", Can fly "
  32. else:
  33. can_fly = " "
  34.  
  35.  
  36. hero = adjective + " " + colour + " \n" + speedy + agile + can_fly + "at " + str(slider)+"mph" + "\n and are a " + superhero + " " + animal
  37. lbl_output.value = "You are... The " + hero + "."
  38. lbl_output.bg = "blue"
  39. lbl_output.text_color = "white"
  40.  
  41. #GUI widgets
  42. picture = Picture(app, image = "D:\#CPD\CPD 2019\Future Learn\programming with GUIs\Week 1\superhero.gif")
  43.  
  44.  
  45. message1 = Text(app, text="Choose an adjective")
  46. cmb_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Fantastic", "Emotional", "Delightful"], selected="Amazing", width = 20)
  47.  
  48.  
  49. message2 = Text(app, text="Enter a colour?", color="black")
  50. lb_colour = ListBox(
  51. app,
  52. items=["red", "green", "blue", "yellow", "purple", "turquoise", "pink", "orange", "black", "brown", "cyan"],
  53. selected="black",
  54. command=change_color,
  55. scrollbar=True)
  56.  
  57.  
  58. message3 = Text(app, text="Pick an animal")
  59. cmb_animal = Combo(app, options=["Aardvark", "Badger", "Cat", "Dolphin", "Okapi", "Elephant", "Lion", "Tiger", "Velociraptor"], selected="Aardvark", width=20)
  60.  
  61.  
  62. message4 = Text(app, text = "choose an ability")
  63. cb_speedy = CheckBox(app, text="Add Speedy")
  64. cb_agile = CheckBox(app, text="Add Agile")
  65. cb_can_fly = CheckBox(app, text="Add Can fly")
  66.  
  67. message5 = Text(app, text = "so how fast, agile, fly can you muster?")
  68. sl_amount = Slider(app, command = slider_changed)
  69.  
  70.  
  71. message6 = Text(app, text = "Which is you favourite super hero?")
  72. bgp_superhero = ButtonGroup(app, options =["SpiderMan", "SuperMan", "WonderWomen", "Batman"], selected="none")
  73.  
  74.  
  75.  
  76. lbl_output = Text(app, text="A hero name will appear here")
  77.  
  78. #event triggers
  79. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
  80.  
  81.  
  82.  
  83. # Show the GUI on the screen, start listening to events.
  84. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement