Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero name generator
- from guizero import App, Box, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, ListBox, Slider, Picture
- from random import choice
- app = App(title="Hero-o-matic", width = 1000, height = 400)
- # Lists of things
- list_of_adjectives = ["Cool", "Friendly", "Upsidedown", "Twisted", "Amazing", "Bonny", "Charming", "Delightful"]
- list_of_animals = ["Dog", "Cod", "Unicorn", "Haddock", "Aardvark", "Cat", "Dolphin", "Tiger", "Velociraptor", "Walrus"]
- list_of_colours = ["White", "Black", "Red", "Green", "Blue", "Yellow", "Silver", "Organge", "Beige"]
- list_of_additions = ["Grass", "Super", "SubZero", "Milkshake", "Giganormous", "Nano", "Bestest"]
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = cmb_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- additions = lbx_additions.value
- if additions is None:
- additions = ""
- hero = f"{additions} {adjective} {colour} {animal}"
- lbl_output.value = f"You are... The \n{hero}."
- toggle_pic()
- picture.after(1000, toggle_pic)
- def toggle_pic():
- picture.visible = not picture.visible
- def auto_hero_name():
- if chk_randomise.value == 1:
- adjective = choice(list_of_adjectives)
- colour = choice(list_of_colours)
- animal = choice(list_of_animals)
- additions = choice(list_of_additions)
- lbl_output.value = f"You are... The\n{additions} {adjective} {colour} {animal}."
- else:
- lbl_output.value = f"A hero name will appear here"
- def colourchange():
- if sld_colour.value == 0:
- app.bg = "light gray"
- app.text_color = "black"
- elif sld_colour.value == 1:
- app.bg = "black"
- app.text_color = "light gray"
- #box structure
- box_settings = Box(app, align="right", width=150, height=150)
- box_selection = Box(app, align="left", width=300, height=400)
- box_in_box_selection = Box(box_selection, align="right", width=150, height=50, border = 2)
- # Your GUI widgets
- #popin picture
- picture = Picture(app, visible = False, image="boom.jpg")
- message_random = Text(box_in_box_selection, text=f"Randomise", width=100)
- chk_randomise = CheckBox(box_in_box_selection, command=auto_hero_name)
- #Selection
- message1 = Text(box_selection, text=f"Choose an adjective")
- cmb_adjective = Combo(box_selection, options=list_of_adjectives, selected="Amazing")
- message2 = Text(box_selection, text=f"Enter a colour?")
- txt_colour = TextBox(box_selection)
- message3 = Text(box_selection, text=f"Pick an animal")
- cmb_animal = Combo(box_selection, options=list_of_animals, selected="Aardvark", width=20)
- message4 = Text(box_selection, text=f"prefix with...")
- lbx_additions = ListBox(box_selection, items=list_of_additions, width = 100, height = 120)
- #Settings
- sld_message = Text(box_settings, text=f"Day/Night colours")
- sld_colour = Slider(box_settings, command = colourchange, start = 0, end = 1, width = 60)
- sld_colour.text_size=1
- #DoIt
- btn_make_name = PushButton(app, text=f'Make me a hero', command = make_hero_name, align = "bottom", width = "fill")
- btn_make_name.bg = "gray"
- btn_make_name.text_color = "yellow"
- btn_make_name.text_size = 26
- lbl_output = TextBox(app, text=f"A hero name will appear here", multiline = True, align = "bottom", width = "fill", height = "fill")
- lbl_output.font = "Jokerman"
- lbl_output.text_size = 26
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement