Advertisement
zhongnaomi

gui 8

Jan 1st, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. # guizero - Hero name generator 3 Add another part to the superhero name, perhaps using checkboxes
  2. from guizero import App, Text, Combo, PushButton, TextBox,CheckBox
  3. app = App(title="Hero-o-matic")
  4.  
  5. # Function definitions for your events go here.
  6. def pick_animal() :
  7.     if cmb_animal1.value ==1:
  8.    
  9.         message4.value=cmb_animal1.text
  10.     if cmb_animal2.value ==1:
  11.    
  12.         message4.value=cmb_animal2.text
  13.        
  14.     if cmb_animal3.value ==1:
  15.    
  16.         message4.value=cmb_animal3.text
  17.     if cmb_animal4.value ==1:
  18.    
  19.         message4.value=cmb_animal4.text
  20.        
  21.     if cmb_animal5.value ==1:
  22.    
  23.         message4.value=cmb_animal5.text
  24. def make_hero_name():
  25.     adjective = bgp_adjective.value
  26.     colour = txt_colour.value
  27.     animal=message4.value
  28.     hero = adjective + " " + colour + " " + animal
  29.     lbl_output.value = "You are... The " + hero + "."
  30.    
  31.  
  32.    
  33. # Your GUI widgets go here
  34. message1 = Text(app, text="Choose an adjective")
  35. bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful","funny","lovely"], selected="Amazing")
  36.  
  37. message2 = Text(app, text="Enter a colour?")
  38. txt_colour = TextBox(app)
  39.  
  40. message3 = Text(app, text="Pick an animal")
  41. cmb_animal1 = CheckBox(app, text="Aardvark",command=pick_animal)
  42. cmb_animal2 = CheckBox(app, text="Badger",command=pick_animal)
  43. cmb_animal3 = CheckBox(app, text="Cat",command=pick_animal)
  44. cmb_animal4 = CheckBox(app, text="Velociraptor",command=pick_animal)
  45. cmb_animal5 = CheckBox(app, text="tutle",command=pick_animal)
  46.  
  47. message4 = Text(app,text="A animal's name will appear here")
  48.  
  49. btn_make_name = PushButton(app, text='Make me a hero',command=make_hero_name)
  50. lbl_output = Text(app, text="A hero name will appear here")
  51.  
  52. # Set up event triggers here
  53.  
  54. # Show the GUI on the screen, start listening to events.
  55. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement