JAWarr

Super hero name creator

Aug 15th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. # guizero - Hero name generator - John Warr 15/08/2020
  2.  
  3. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox
  4. app = App(title="Hero-o-matic")
  5.  
  6. # Function definitions for your events go here.
  7. def make_hero_name():
  8.     adjective = bgp_adjective.value
  9.     colour = txt_colour.value
  10.     animal = cmb_animal.value
  11.     if checkbox.value == 1:
  12.         title ="Super"
  13.     else:
  14.         title =""
  15.     hero = title + " " + adjective + " " + colour.capitalize() + " " + animal
  16.     lbl_output.text_color = "green"
  17.     lbl_output.value = "You are... The " + hero + "."
  18.  
  19. # Your GUI widgets go here
  20. message1 = Text(app, text="Choose an adjective")
  21. bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Dude", "Effervescent"], selected="Amazing", width=20)
  22.  
  23. message2 = Text(app, text="Enter a colour?")
  24. txt_colour = TextBox(app, width=20)
  25.  
  26. message3 = Text(app, text="Pick an animal")
  27. cmb_animal = ButtonGroup(app, options=["Aardvark", "Badger", "Dolphin", "Velociraptor", "Goat"], selected="Aardvark", width=20)
  28.  
  29. checkbox = CheckBox(app, text="Add Super Title")
  30.  
  31. # Set up event triggers here
  32.  
  33. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name, width=20)
  34. btn_make_name.bg="lightgreen"
  35. lbl_output = Text(app, text="A hero name will appear here")
  36.  
  37. # Show the GUI on the screen, start listening to events.
  38. app.display()
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment