Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero name generator , boxes version
- from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, CheckBox, Picture, ListBox, Box
- app = App(title="Central Europe Hero-o-matic :-) ", height=660, width=740)
- # Function definitions go here.
- def make_hero_name():
- colour = " "
- ckb_second_adjective_str = " "
- great_name = " "
- if ckb_second_adjective.value == 1:
- ckb_second_adjective_str = ckb_second_adjective.text
- if str(lbx_add_gname.value) != "None":
- great_name = lbx_add_gname.value
- adjective = cmb_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- hero = adjective + " " + colour + " " + ckb_second_adjective_str + " " + animal + " " + great_name
- lbl_output.text_size = 20
- lbl_output.value = "You are... The " + hero + "."
- def dark_mode():
- if ckb_dark_mode.value == 1:
- app.bg = "black"
- app.text_color = "white"
- else:
- app.bg = "light grey"
- app.text_color = "black"
- # GUI widgets go here
- box_one = Box(app, align="top", width="fill", border=2)
- box_one.bg = "green"
- pic = Picture(box_one, image="heroes.jpeg")
- ckb_dark_mode = CheckBox(app, text="Dark Mode", command=dark_mode)
- box_two = Box(app, align="top", width="fill", border=2)
- box_two.bg = "firebrick"
- message1 = Text(box_two, text="Choose an adjective")
- cmb_adjective = Combo(box_two, options=["Patriotic", "Persistent","Heroic","Brave", "Steadfast", "National"], selected="Patriotic", width=20)
- box_three = Box(app, align="top", width="fill", border=2)
- box_three.bg = "olive drab"
- message2 = Text(box_three, text="Enter a colour?")
- txt_colour = TextBox(box_three)
- box_four = Box(app, align="top", width="fill", border=2)
- box_four.bg = "lawn green"
- message3 = Text(box_four, text="Pick an animal")
- cmb_animal = Combo(box_four, options=["Wolf", "Wolverine" , "Bear", "Boar", "Eagle", "Moose", "Deer"], selected="Wolverine", width=20)
- box_five = Box(app, align="top", width="fill", border=2)
- box_five.bg = "sienna"
- message4 = Text(box_five, text="Choose a second adjective")
- ckb_second_adjective = CheckBox(box_five, text="Mighty")
- message5 = Text(box_five, text="Additional great name")
- lbx_add_gname = ListBox(box_five, items=["The Great Warrior", "The Best Hunter", "The Sky Conqueror"], height = 80, width=160)
- lbl_output = Text(app, text="A hero name will appear here")
- # Set up event triggers here
- btn_make_name = PushButton(app, text='Make me a hero', command=make_hero_name)
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement