Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Text, TextBox, ButtonGroup, PushButton, Combo, CheckBox, info
- app = App(title="Hero name generator")
- # Function definitions for your events go here.
- def btn_go_clicked():
- # Set attributes based on checkbox
- hero = choice_adj.value + " " + choice_colour.value + " " + show_strengths() + " " + choice_animal.value
- info("Greetings","Your are the " + hero)
- # Process checkboxes
- def show_strengths():
- strengths = ""
- if box_fly.value == 1:
- strengths = strengths + " " + "flying"
- if box_swim.value == 1:
- strengths = strengths + " " + "swimming"
- if box_dance.value == 1:
- strengths = strengths + " " + "dancing"
- return strengths
- # Start with a pre-determined list of adjectives
- lbl_adj = Text(app, text="Choose an adjective")
- choice_adj = ButtonGroup(app,options=["hairy","tiny","ridiculous"])
- # Free format colour choice
- lbl_colour = Text(app, text="Enter your colour")
- choice_colour = TextBox(app)
- # Checkboxes for physical attributes
- # Initialise strengths
- strengths = ""
- lbl_attributes = Text(app, "What can you do?")
- box_fly = CheckBox (app, text = "flying")
- box_swim = CheckBox (app, text = "swimming")
- box_dance = CheckBox (app, text = "dancing")
- # Combobox for animal
- lbl_animal = Text(app, text="Pick an animal")
- choice_animal = Combo(app,options=["Cat","Dog","Mouse"])
- # Button to generate name and favourite animal
- btn_go = PushButton(app, command=btn_go_clicked, text="Done")
- # Show the GUI on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement