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