Advertisement
wayne_li

try1

Aug 18th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, ListBox, CheckBox, Picture, Box
  3. app = App(title="Hero-o-matic", width=500, height=430)
  4.  
  5. # Function definitions for your events go here.
  6. def make_hero_name():
  7. adjective = bgp_adjective.value
  8. colour = '-'.join(listbox.value) if listbox.value else ''
  9. animal = cmb_animal.value
  10. gender = btg_gender.value
  11. hero = adjective + " " + colour + " " + animal + " " + gender
  12. lbl_output.value = "You are... The " + hero + "."
  13.  
  14. def toggle_mode():
  15. app.text_color = "black" if checkbox_mode.value == 0 else "white"
  16. box1.bg = "#ccff00" if checkbox_mode.value == 0 else "#880000"
  17. box2.bg = "#99ff33" if checkbox_mode.value == 0 else "#660022"
  18. box3.bg = "#66ff66" if checkbox_mode.value == 0 else "#440044"
  19. box4.bg = "#33ff99" if checkbox_mode.value == 0 else "#220066"
  20. box5.bg = "#00ffcc" if checkbox_mode.value == 0 else "#000088"
  21.  
  22. # Your GUI widgets go here
  23. #picture = Picture(app, image="201908.png")
  24.  
  25. box2 = Box(app, align="top", width="fill", height = 50, border=1)
  26. message2 = Text(box2, text="Coose one or more colour")
  27. listbox = ListBox(box2, items=["blue", "orange", "green", "red", "yellow", "purple", "white"], multiselect=True, scrollbar=True, width=200, height=60)
  28. box2.bg = "#99ff33"
  29.  
  30. box3 = Box(app, align="top", width="fill", height = 50, border=1)
  31. message3 = Text(box3, text="Pick an animal")
  32. cmb_animal = Combo(box3, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
  33. box3.bg = "#66ff66"
  34.  
  35. box6 = Box(app, align="bottom", width="fill", height = 30, border=1)
  36. checkbox_mode = CheckBox(box6, text="Dark mode", align="right", command=toggle_mode)
  37.  
  38. box5 = Box(app, align="bottom", width="fill", height = 100, border=1)
  39. btn_make_name = PushButton(box5, text='Make me a hero', command=make_hero_name)
  40. lbl_output = Text(box5, text="A hero name will appear here")
  41. box5.bg = "#00ffcc"
  42.  
  43.  
  44. box1 = Box(app, align="left", width="250", height = 200, border=1)
  45. message1 = Text(box1, text="Choose an adjective")
  46. bgp_adjective = ButtonGroup(box1, options=["Amazing", "Bonny", "Charming", "Delightful"], selected="Amazing")
  47. box1.bg = "#ccff00"
  48.  
  49. box4 = Box(app, align="right", width="300", height = 200, border=1)
  50. message4= Text (box4, text="Choose a gender:")
  51. btg_gender = ButtonGroup(box4, options=["Girl", "Boy", "Woman", "Man"])
  52. box4.bg = "#33ff99"
  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