Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero challenge generator
- from guizero import App, Text, ButtonGroup, Combo, ListBox, PushButton, TextBox, CheckBox, Slider, Picture
- app = App(title="Hero-challenge", bg = "grey", height = 900, width =380 )
- # Function definitions
- def slider_changed(slider_value):
- sl_amount.value = slider_value
- def change_color(value):
- lb_colour.text_color = value
- def make_hero_name():
- adjective = cmb_adjective.value
- colour = lb_colour.value
- animal = cmb_animal.value
- slider = sl_amount.value
- superhero = bgp_superhero.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 + " \n" + speedy + agile + can_fly + "at " + str(slider)+"mph" + "\n and are a " + superhero + " " + animal
- lbl_output.value = "You are... The " + hero + "."
- lbl_output.bg = "blue"
- lbl_output.text_color = "white"
- #GUI widgets
- picture = Picture(app, image = "D:\#CPD\CPD 2019\Future Learn\programming with GUIs\Week 1\superhero.gif")
- 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?", color="black")
- lb_colour = ListBox(
- app,
- items=["red", "green", "blue", "yellow", "purple", "turquoise", "pink", "orange", "black", "brown", "cyan"],
- selected="black",
- command=change_color,
- scrollbar=True)
- 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")
- message5 = Text(app, text = "so how fast, agile, fly can you muster?")
- sl_amount = Slider(app, command = slider_changed)
- message6 = Text(app, text = "Which is you favourite super hero?")
- bgp_superhero = ButtonGroup(app, options =["SpiderMan", "SuperMan", "WonderWomen", "Batman"], selected="none")
- lbl_output = Text(app, text="A hero name will appear here")
- #event triggers
- 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