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
- app = App(title="Hero-o-matic")
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = cmb_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- if cb_speedy.value == 1:
- speedy = ", Speedy"
- else:
- speedy = ""
- if cb_agile.value == 1:
- agile = ", Agile"
- else:
- agile= ""
- if cb_can_fly.value == 1:
- can_fly = ", Can fly "
- else:
- can_fly = " "
- hero = adjective + " " + colour + " " + speedy + agile+ can_fly + animal
- lbl_output.value = "You are... The " + hero + "."
- # Your GUI widgets go here
- message1 = Text(app, text="Choose an adjective")
- cmb_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Fantastic", "Emotional", "Delightful"], selected="Amazing", width = 20)
- message2 = Text(app, text="Enter a colour?")
- txt_colour = TextBox(app)
- message3 = Text(app, text="Pick an animal")
- cmb_animal = Combo(app, options=["Aardvark", "Badger", "Cat", "Dolphin", "Okapi", "Elephant", "Lion", "Tiger", "Velociraptor"], selected="Aardvark", width=20)
- message4 = Text(app, text = "choose an ability")
- cb_speedy = CheckBox(app, text="Add Speedy")
- cb_agile = CheckBox(app, text="Add Agile")
- cb_can_fly = CheckBox(app, text="Add Can fly")
- lbl_output = Text(app, text="A hero name will appear here")
- # Set up event triggers here
- btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement