Advertisement
Guest User

Untitled

a guest
Feb 13th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. from guizero import App, Text, TextBox, ButtonGroup, PushButton, Combo, CheckBox, info
  2. app = App(title="Hero name generator")
  3.  
  4. # Function definitions for your events go here.
  5. def btn_go_clicked():
  6. # Set attributes based on checkbox
  7.  
  8. hero = choice_adj.value + " " + choice_colour.value + " " + show_strengths() + " " + choice_animal.value
  9. info("Greetings","Your are the " + hero)
  10.  
  11. # Process checkboxes
  12. def show_strengths():
  13.  
  14. strengths = ""
  15.  
  16. if box_fly.value == 1:
  17. strengths = strengths + " " + "flying"
  18. if box_swim.value == 1:
  19. strengths = strengths + " " + "swimming"
  20. if box_dance.value == 1:
  21. strengths = strengths + " " + "dancing"
  22.  
  23. return strengths
  24.  
  25. # Start with a pre-determined list of adjectives
  26. lbl_adj = Text(app, text="Choose an adjective")
  27. choice_adj = ButtonGroup(app,options=["hairy","tiny","ridiculous"])
  28. # Free format colour choice
  29. lbl_colour = Text(app, text="Enter your colour")
  30. choice_colour = TextBox(app)
  31. # Checkboxes for physical attributes
  32.  
  33. # Initialise strengths
  34. strengths = ""
  35.  
  36. lbl_attributes = Text(app, "What can you do?")
  37. box_fly = CheckBox (app, text = "flying")
  38. box_swim = CheckBox (app, text = "swimming")
  39. box_dance = CheckBox (app, text = "dancing")
  40.  
  41. # Combobox for animal
  42. lbl_animal = Text(app, text="Pick an animal")
  43. choice_animal = Combo(app,options=["Cat","Dog","Mouse"])
  44.  
  45. # Button to generate name and favourite animal
  46.  
  47. btn_go = PushButton(app, command=btn_go_clicked, text="Done")
  48.  
  49. # Show the GUI on the screen
  50. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement