Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero name generator
- from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, Picture
- app = App(title="Hero-o-matic", width=400, height=700, bg="light blue")
- # Function definitions
- def make_dark_mode ():
- if chk_dark.value == 1:
- app.bg="black"
- app.text_color = "white"
- else:
- app.bg="light blue"
- app.text_color = "black"
- def make_hero_name():
- if chk_veg.value == 1:
- veg = "vegeterian"
- else:
- veg = ""
- adjective = cmb_adjective.value
- colour = txt_colour.value
- animal = btg_animal.value
- gender = btg_gender.value
- hero = adjective + " " + colour + " " + veg + " " + animal + " " + gender
- lbl_output.value = "You are... The " + hero + "."
- #GUI widgets
- picture = Picture(app, image="superhero.png")
- chk_dark = CheckBox (app, text="Dark Mode", command=make_dark_mode)
- message1 = Text(app, text="Pick an adjective")
- cmb_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful", "Incredible", "Fantastic"], selected="Incredible", width=25)
- message2 = Text(app, text="Enter a colour?")
- txt_colour = TextBox(app)
- chk_veg = CheckBox (app, text="Vegetarian")
- message3 = Text(app, text="Choose an animal")
- btg_animal = ButtonGroup(app, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor", "Dog", "Lion", "Bat"], width=20)
- message4= Text (app, text="Choose a gender:")
- btg_gender = ButtonGroup(app, options=["Man", "Woman"])
- # event triggers
- btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
- lbl_output = Text(app, text="A hero name will appear here")
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement