Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero name generator
- from guizero import *
- app = App(title="Hero-o-matic", width=420, height=620, bg="plum1")
- app.font_size="11"
- # Function definitions
- def make_dark_mode ():
- if chk_dark.value == 1:
- app.bg="black"
- app.text_color = "white"
- else:
- app.bg="plum1"
- app.text_color = "black"
- def make_hero_name():
- if chk_veg.value == 1:
- veg = "vegeterian"
- else:
- veg = ""
- adjective = cmb_adjective.value
- colour = txt_colour.value
- animal = btg_animal.value
- gender = btg_gender.value
- hero = adjective + " " + colour + " " + veg + " " + animal + " " + gender
- lbl_output.value = "You are... The " + hero + "."
- #GUI widgets
- box_picture=Box(app, border=2)
- picture = Picture(box_picture, image="superhero.png")
- box_dark=Box(app)
- box_dark.text_size="11"
- chk_dark = CheckBox (box_dark, text="Dark Mode", command=make_dark_mode)
- box_box=Box(app, height=120, width="fill", border=1)
- box_box.bg="plum2"
- box_box.font ="Calibri"
- box_box.font_size="11"
- box_adjective=Box(box_box, width=200, height=120, align="left")
- message1 = Text(box_adjective, text="Pick an adjective")
- cmb_adjective = Combo(box_adjective, options=["Amazing", "Bonny", "Charming", "Delightful", "Incredible", "Fantastic"], selected="Incredible", width=25)
- box_colour = Box(box_box, width=200, height=120, align="right")
- message2 = Text(box_colour, text="Enter a colour?")
- txt_colour = TextBox(box_colour, width=25)
- chk_veg = CheckBox (app)
- chk_veg.text_size="11"
- chk_veg.text="Vegetarian"
- box_box2=Box(app, width="fill", height="200", border=1)
- box_box2.bg="orchid1"
- box_animal=Box(box_box2, width="200", height="200", align="left")
- message3 = Text(box_animal, text="Choose an animal")
- btg_animal = ButtonGroup(box_animal, options=["Aardvark", "Badger", "Cat", "Dolphin", "Velociraptor", "Dog", "Lion", "Bat"], width=20)
- box_gender=Box(box_box2, width="200", height="200", align="top")
- message4= Text (box_gender, text="Choose a gender:")
- btg_gender = ButtonGroup(box_gender, options=["Man", "Woman"])
- # event triggers
- box=Box(app, width="fill", border=1)
- box.bg="plum1"
- btn_make_name = PushButton(box, text='Make me a hero', command=make_hero_name)
- btn_make_name.bg = "plum3"
- lbl_output = Text(box, text="A hero name will appear here")
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement