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, ListBox, CheckBox, Picture, Box
- app = App(title="Hero-o-matic", width=500, height=430)
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = bgp_adjective.value
- colour = '-'.join(listbox.value) if listbox.value else ''
- animal = cmb_animal.value
- gender = btg_gender.value
- hero = adjective + " " + colour + " " + animal + " " + gender
- lbl_output.value = "You are... The " + hero + "."
- def toggle_mode():
- app.text_color = "black" if checkbox_mode.value == 0 else "white"
- box1.bg = "#ccff00" if checkbox_mode.value == 0 else "#880000"
- box2.bg = "#99ff33" if checkbox_mode.value == 0 else "#660022"
- box3.bg = "#66ff66" if checkbox_mode.value == 0 else "#440044"
- box4.bg = "#33ff99" if checkbox_mode.value == 0 else "#220066"
- box5.bg = "#00ffcc" if checkbox_mode.value == 0 else "#000088"
- # Your GUI widgets go here
- #picture = Picture(app, image="201908.png")
- box2 = Box(app, align="top", width="fill", height = 50, border=1)
- message2 = Text(box2, text="Coose one or more colour")
- listbox = ListBox(box2, items=["blue", "orange", "green", "red", "yellow", "purple", "white"], multiselect=True, scrollbar=True, width=200, height=60)
- box2.bg = "#99ff33"
- box3 = Box(app, align="top", width="fill", height = 50, border=1)
- message3 = Text(box3, text="Pick an animal")
- cmb_animal = Combo(box3, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
- box3.bg = "#66ff66"
- box6 = Box(app, align="bottom", width="fill", height = 30, border=1)
- checkbox_mode = CheckBox(box6, text="Dark mode", align="right", command=toggle_mode)
- box5 = Box(app, align="bottom", width="fill", height = 100, border=1)
- btn_make_name = PushButton(box5, text='Make me a hero', command=make_hero_name)
- lbl_output = Text(box5, text="A hero name will appear here")
- box5.bg = "#00ffcc"
- box1 = Box(app, align="left", width="250", height = 200, border=1)
- message1 = Text(box1, text="Choose an adjective")
- bgp_adjective = ButtonGroup(box1, options=["Amazing", "Bonny", "Charming", "Delightful"], selected="Amazing")
- box1.bg = "#ccff00"
- box4 = Box(app, align="right", width="300", height = 200, border=1)
- message4= Text (box4, text="Choose a gender:")
- btg_gender = ButtonGroup(box4, options=["Girl", "Boy", "Woman", "Man"])
- box4.bg = "#33ff99"
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement