Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import libraries
- from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, ListBox, Picture
- app = App(title="My-Hero", width=700, height=600)
- #Name generator function
- def make_hero():
- start_adjectives = cmb_adj1.value
- colour = cmb_clr.value
- animal = cmb_aml.value
- end_adjective = cmb_adj2.value
- planet = txt_planet.value
- hero = start_adjectives + " " + colour + " " + animal + " " + end_adjective + " from the planet " + planet
- lbl_output.value = "You are... the " + hero + "!"
- #dark mode function
- def dark_mode():
- app.bg = "black"
- txt_adj1.text_color = "white"
- cmb_adj1.text_color = "white"
- txt_clr.text_color = "white"
- cmb_clr.text_color = "white"
- txt_aml.text_color = "white"
- cmb_aml.text_color = "white"
- txt_adj2.text_color = "white"
- cmb_adj2.text_color = "white"
- txt_pt.text_color = "white"
- txt_planet.text_color = "white"
- txt_drk.text_color = "white"
- chk_drk.text_color = "white"
- btn_name.text_color = "white"
- lbl_output.text_color = "white"
- #GUI widgets
- pic = Picture(app, image = "/home/pi/Desktop/super-dog.png", height=50, width=200)
- txt_adj1 = Text(app, text="Select your start adjectives")
- cmb_adj1 = Combo(app, options = ["Amazing", "Malicious", "Brave", "Stupendous", "Zany"], selected = "Amazing", width=20)
- txt_clr = Text(app, text = "Choose your colour")
- cmb_clr = Combo(app, options = ["Red", "Blue", "Yellow"], selected = "Red", width=20)
- txt_aml = Text(app, text = "Choose your animal")
- cmb_aml = Combo(app, options = ["Aardvark", "Bear", "Deer", "Dog", "Owl", "Turtle", "Zebra"], selected = "Aardvark", width = 20)
- txt_adj2 = Text(app, text="Select your end adjective")
- cmb_adj2 = Combo(app, options = [" of doom", " of power", "of terror", " of awesome"], selected = " of doom", width=20)
- txt_pt = Text(app, text = "Enter your home planet")
- txt_planet = TextBox(app)
- txt_drk = Text(app, text = "Enable dark mode?")
- chk_drk = CheckBox(app, text = "Turn on dark mode!", command = dark_mode)
- btn_name = PushButton(app, text="Make my Hero", command = make_hero)
- lbl_output = Text(app, text="A hero will appear here")
- #Show GUI; wait for events
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement