Advertisement
bensimmo

Untitled

Feb 4th, 2021
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Box, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, ListBox, Slider, Picture
  3. from random import choice
  4. app = App(title="Hero-o-matic", width = 1000, height = 400)
  5.  
  6. # Lists of things
  7. list_of_adjectives = ["Cool", "Friendly", "Upsidedown", "Twisted", "Amazing", "Bonny", "Charming", "Delightful"]
  8. list_of_animals = ["Dog", "Cod", "Unicorn", "Haddock", "Aardvark", "Cat", "Dolphin", "Tiger", "Velociraptor", "Walrus"]
  9. list_of_colours = ["White", "Black", "Red", "Green", "Blue", "Yellow", "Silver", "Organge", "Beige"]
  10. list_of_additions = ["Grass", "Super", "SubZero", "Milkshake", "Giganormous", "Nano", "Bestest"]
  11.  
  12. # Function definitions for your events go here.
  13. def make_hero_name():
  14.     adjective = cmb_adjective.value
  15.     colour = txt_colour.value
  16.     animal = cmb_animal.value
  17.     additions = lbx_additions.value
  18.     if additions is None:
  19.         additions = ""
  20.     hero = f"{additions} {adjective} {colour} {animal}"
  21.     lbl_output.value = f"You are... The \n{hero}."
  22.     toggle_pic()
  23.     picture.after(1000, toggle_pic)
  24.    
  25. def toggle_pic():
  26.     picture.visible = not picture.visible
  27.  
  28. def auto_hero_name():
  29.     if chk_randomise.value == 1:
  30.         adjective = choice(list_of_adjectives)
  31.         colour = choice(list_of_colours)
  32.         animal = choice(list_of_animals)
  33.         additions = choice(list_of_additions)
  34.  
  35.         lbl_output.value = f"You are... The\n{additions} {adjective} {colour} {animal}."
  36.     else:
  37.         lbl_output.value = f"A hero name will appear here"
  38.  
  39. def colourchange():
  40.     if sld_colour.value == 0:
  41.         app.bg = "light gray"
  42.         app.text_color = "black"
  43.     elif sld_colour.value == 1:
  44.         app.bg = "black"
  45.         app.text_color = "light gray"
  46.    
  47. #box structure
  48. box_settings = Box(app, align="right", width=150, height=150)
  49. box_selection = Box(app, align="left", width=300, height=400)
  50. box_in_box_selection = Box(box_selection, align="right", width=150, height=50, border = 2)
  51.  
  52. # Your GUI widgets
  53. #popin picture
  54. picture = Picture(app, visible = False, image="boom.jpg")
  55.  
  56. message_random = Text(box_in_box_selection, text=f"Randomise", width=100)
  57. chk_randomise = CheckBox(box_in_box_selection, command=auto_hero_name)
  58.  
  59. #Selection
  60. message1 = Text(box_selection, text=f"Choose an adjective")
  61. cmb_adjective = Combo(box_selection, options=list_of_adjectives, selected="Amazing")
  62.  
  63. message2 = Text(box_selection, text=f"Enter a colour?")
  64. txt_colour = TextBox(box_selection)
  65.  
  66. message3 = Text(box_selection, text=f"Pick an animal")
  67. cmb_animal = Combo(box_selection, options=list_of_animals, selected="Aardvark", width=20)
  68.  
  69. message4 = Text(box_selection, text=f"prefix with...")
  70. lbx_additions = ListBox(box_selection, items=list_of_additions, width = 100, height = 120)
  71.  
  72. #Settings
  73. sld_message = Text(box_settings, text=f"Day/Night colours")
  74. sld_colour = Slider(box_settings, command = colourchange, start = 0, end = 1, width = 60)
  75. sld_colour.text_size=1
  76.  
  77. #DoIt
  78. btn_make_name = PushButton(app, text=f'Make me a hero', command = make_hero_name, align = "bottom", width = "fill")
  79. btn_make_name.bg = "gray"
  80. btn_make_name.text_color = "yellow"
  81. btn_make_name.text_size = 26
  82. lbl_output = TextBox(app, text=f"A hero name will appear here", multiline = True, align = "bottom", width = "fill", height = "fill")
  83. lbl_output.font = "Jokerman"
  84. lbl_output.text_size = 26
  85.  
  86.  
  87. # Show the GUI on the screen, start listening to events.
  88. app.display()
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement