Advertisement
Vesna_To

hero2

Aug 3rd, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, Picture
  3. app = App(title="Hero-o-matic", width=400, height=700, bg="light blue")
  4.  
  5. # Function definitions
  6. def make_dark_mode ():
  7. if chk_dark.value == 1:
  8. app.bg="black"
  9. app.text_color = "white"
  10.  
  11. else:
  12. app.bg="light blue"
  13. app.text_color = "black"
  14.  
  15. def make_hero_name():
  16. if chk_veg.value == 1:
  17. veg = "vegeterian"
  18. else:
  19. veg = ""
  20. adjective = cmb_adjective.value
  21. colour = txt_colour.value
  22. animal = btg_animal.value
  23. gender = btg_gender.value
  24. hero = adjective + " " + colour + " " + veg + " " + animal + " " + gender
  25. lbl_output.value = "You are... The " + hero + "."
  26.  
  27. #GUI widgets
  28. picture = Picture(app, image="superhero.png")
  29. chk_dark = CheckBox (app, text="Dark Mode", command=make_dark_mode)
  30. message1 = Text(app, text="Pick an adjective")
  31. cmb_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful", "Incredible", "Fantastic"], selected="Incredible", width=25)
  32.  
  33. message2 = Text(app, text="Enter a colour?")
  34. txt_colour = TextBox(app)
  35.  
  36. chk_veg = CheckBox (app, text="Vegetarian")
  37.  
  38. message3 = Text(app, text="Choose an animal")
  39. btg_animal = ButtonGroup(app, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor", "Dog", "Lion", "Bat"], width=20)
  40.  
  41. message4= Text (app, text="Choose a gender:")
  42. btg_gender = ButtonGroup(app, options=["Man", "Woman"])
  43.  
  44. # event triggers
  45. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
  46. lbl_output = Text(app, text="A hero name will appear here")
  47.  
  48. # Show the GUI on the screen, start listening to events.
  49. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement