Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -------------------------------------------------------------------
- # Programming with GUIs Raspberry Pi Foundation
- # Section 1.9
- # The Super Hero Name Generator
- # -------------------------------------------------------------------
- from guizero import App, ButtonGroup, CheckBox, Combo, ListBox, Picture, PushButton, Text, TextBox
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = bgp_adjective.value
- adj2 = lbox_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- hero = adjective + " " + adj2 + " " + colour + " " + animal
- lbl_output.value = "You are... The " + hero + "."
- def toggle_background():
- if bgrd_select.value == 1 :
- bgcolor = "black"
- fgcolor = "white"
- bgrd_select.text = "White background"
- else :
- bgcolor = "white"
- fgcolor = "black"
- bgrd_select.text = "Dark background"
- app.bg = bgcolor
- message1.text_color = fgcolor
- message1a.text_color = fgcolor
- message1b.text_color = fgcolor
- message2.text_color = fgcolor
- txt_colour.text_color = fgcolor
- message3.text_color = fgcolor
- bgp_adjective.text_color = fgcolor
- lbox_adjective.text_color = fgcolor
- cmb_animal.text_color = fgcolor
- lbl_output.text_color = fgcolor
- btn_make_name.text_color = fgcolor
- bgrd_select.text_color = fgcolor
- app = App(title="Super Hero Name Generator",
- width=400,
- height=600)
- # GUI widgets go here
- picture = Picture(app, image="images/alien.png")
- message1 = Text(app, text="To find the perfect name for your super hero",
- align="left")
- message1a = Text(app, text="select the best fit from",
- align="left")
- bgp_adjective = Combo(app,
- options=["Awkward", "Bright", "Clueless", "Disgraceful", "Emotional", "Facetious", "Gigantic",
- "Inocent", "Maverick", "Spooky", "Wicked"],
- selected="Inocent",
- align="left")
- message1b = Text(app, text="and also from",
- align="left")
- lbox_adjective = ListBox(app,
- items=["Cheerful", "Geeky", "Mindless", "Obnoxious", "Willful"],
- align="left")
- message2 = Text(app, text="Pick a colour for the uniform")
- txt_colour = TextBox(app,text="Invisible")
- message3 = Text(app, text="What animal more closely resembles the hero?")
- cmb_animal = Combo(app,
- options=["Ant", "Beetle", "Cat", "Dolphin", "Gazele", "Hipo","Sloth", "Velociraptor", "Whale"],
- selected="Ant")
- cmb_animal.width=20
- lbl_output = Text(app, text="A hero name will appear here")
- btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name, grid=[100,20])
- bgrd_select = CheckBox(app, text="Dark background",command=toggle_background)
- # Set up event triggers here
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement