Advertisement
zhongnaomi

make me hero gui 8

Sep 11th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox,ListBox
  3. app = App(title="Hero-o-matic",height=700, width=400)
  4. # Function definitions for your events go here.
  5. def pickhero(value):
  6.     superhero_name.value = value
  7. def make_hero_name():
  8.  
  9.     superheroname = superhero_name.value
  10.     adjective = bgp_adjective.value
  11.     colour = txt_colour.value
  12.     animal = cmb_animal.value
  13.     hero = adjective + " " + colour + " " + animal
  14.     lbl_output.value = "You are  " + superheroname + " . The " + hero + "."
  15. def night_or_day_mode():
  16.     if darkmode.value == 1:
  17.         app.bg = "black"
  18.         app.text_color = "white"
  19.     else:
  20.         app.bg = "white"
  21.         app.text_color = "black"
  22.        
  23.  
  24.    
  25. # Your GUI widgets go here  
  26. darkmode = CheckBox (app, text ="night mode", command = night_or_day_mode)
  27. message1 = Text(app, text="Choose an adjective")
  28. bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful","Lovely"], selected="Bonny", width=20)
  29. message2 = Text(app, text="Enter a colour?")
  30. txt_colour = TextBox(app)
  31. message3 = Text(app, text="Pick an animal")
  32. cmb_animal = ButtonGroup(app, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor","Turtle","Dog"], selected="Turtle")
  33. questions_superhero = Text(app, text="Pick a name of superhero?")
  34. pick_superhero_name = ListBox(app, items=["supermum", "superdad", "superman"],command =pickhero )
  35. superhero_name = Text (app, text="Your pick superhero's name will appear here")
  36. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
  37. lbl_output = Text(app, text="A hero name will appear here")
  38.  
  39. # Set up event triggers here
  40.  
  41. # Show the GUI on the screen, start listening to events.
  42. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement