crzcas

improving GUI

Mar 7th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox
  3. app = App(title="Hero-o-matic")
  4. app.bg = "blue"
  5.  
  6. # Function definitions for your events go here.
  7.  
  8. def make_hero_name():
  9.     adjective = bgp_adjective.value
  10.     colour = txt_colour.value
  11.     animal = cmb_animal.value
  12.     fruit = cmb_fruit.value
  13.     hero = adjective + " " + colour + " " + animal+" "+fruit
  14.     lbl_output.value = "You are... The " + hero + "."
  15.  
  16. # Your GUI widgets go here
  17. message1 = Text(app, text="Choose an adjective")
  18. bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful", "Speedy"], selected="Amazing")
  19. message1.text_color = "yellow"
  20.  
  21. message2 = Text(app, text="Enter a colour?")
  22. txt_colour = TextBox(app)
  23. message2.text_color = "yellow"
  24.  
  25. message3 = Text(app, text="Pick an animal")
  26. cmb_animal = Combo(app, options=["Aardvark", "Cat", "Dolphin", "Tiger", "Velociraptor", "Walrus","Seal"], selected="Aardvark", width=20)
  27. message3.text_color = "yellow"
  28.  
  29. message4 = Text(app, text="Pick an fruit")
  30. cmb_fruit = Combo(app, options=["Banana", "Apple", "Plum", "Pear", "Orange", "Grape","Tangerine"], selected="Banana", width=20)
  31. message4.text_color = "yellow"
  32.  
  33. # Set up event triggers here
  34. btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
  35. lbl_output = Text(app, text="A hero name will appear here")
  36. btn_make_name.text_size = 15
  37. btn_make_name.text_color = "red"
  38.  
  39. # Show the GUI on the screen, start listening to events.
  40. app.display()
Advertisement
Add Comment
Please, Sign In to add comment