Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A GUIZero - The Super Splendiferous Superhero name generator (based on FutureLearn Course RPi Foundation)
- from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, Slider, Picture, ListBox, Box
- app = App(title="The Super Splendiferous...", height=950, width=700)
- app.bg = 'yellow'
- app.text_color = "black"
- app.font = 'Stencil'
- dark_light = 1
- # Function definitions for my events here
- def make_hero_name():
- skin=""
- adjective = bgp_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- generation = sli_gen.value
- birthplace = lstbox_plcbirth.value
- if chk_skin_fur.value == 1:
- skin = skin + "furry "
- if chk_skin_scaly.value == 1:
- skin = skin + "scaly "
- if chk_skin_slip.value == 1:
- skin = skin + "slippery "
- hero = adjective + " " + colour + " " + skin + animal + " " + str(generation) + " of " + birthplace
- lbl_output.value = "You are...The " + hero
- #Pushbutton that sets dark or light mode
- def dark_light_mode():
- global dark_light
- if dark_light == 1:
- dark_light = dark_light * -1
- app.bg = 'black'
- app.text_color = 'yellow'
- else:
- dark_light = dark_light * -1
- app.bg = 'yellow'
- app.text_color = 'black'
- # My GUI widgets here
- btn_make_name = PushButton(app, text=' Dark\Light Mode ', command=dark_light_mode)
- box1=Box(app, border=2, width=280, height=230)
- message1 = Text(box1, text="Choose your amazing adjective:")
- bgp_adjective = ButtonGroup(box1, options=["Happy", "Flappy", "Snappy", "Clappy"], selected="Happy", command=make_hero_name)
- message2 = Text(box1, text="Colour:")
- txt_colour = TextBox(box1, command=make_hero_name)
- message3 = Text(box1, text="Favourite animal:")
- cmb_animal = Combo(box1, options=["Anteater", "Bandicote", "Coyote", "Duck", "Eagle", "Frog", "Gerbil", "Hyena", "Iguana", "Jellyfish", "Kakapo", "Llama", "Mole", "Newt"], selected="Anteater", command=make_hero_name)
- box2=Box(app, border=2, width=280, height=170)
- message4 = Text(box2, text="Skin Type:")
- chk_skin_fur = CheckBox(box2, text="Furry ", command=make_hero_name)
- chk_skin_scaly = CheckBox(box2, text="Scaly ", command=make_hero_name)
- chk_skin_slip = CheckBox(box2, text="Slippery ", command=make_hero_name)
- message5 = Text(box2, text="Generation:")
- sli_gen = Slider(box2, start=1, end=3, command=make_hero_name)
- box3=Box(app, border=2, width=280, height=190)
- message6 = Text(box3, text="Place of Birth:")
- lstbox_plcbirth = ListBox(box3, items=["Birmingham","Cambridge", "Cheltenham", "Dundee", "Ely", "London", "Newcastle", "Peterborough", "Potton", "Safron Waldon"], selected="Birmingham", command=make_hero_name)
- #btn_make_name = PushButton(app, text=' Go! ', command=make_hero_name)
- lbl_output = Text(app, text="Hero name being forged...um any moment now...", bg="red", color="yellow")
- #Make sure the GIF image is in the same folder as this Python file
- picture = Picture(app, image='superhero.gif')
- # Show the GUI on the screen, start listening to events.
- app.display()
Add Comment
Please, Sign In to add comment