Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # guizero - Hero name generator .. Box in Box
- # Design principles .. repetition, proximity, ...
- from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, Box
- app = App(title="Hero-o-matic", width=600, height=690)
- app.bg = "#CCCC00"
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = bgp_adjective.value
- colour = txt_cText.value
- animal = cmb_animal.value
- hero = adjective + " " + colour + " " + animal
- lbl_output.value = "You are... The " + hero + "."
- # STYLING: define some Colour constants
- cSubHead = "#FFFFFF"
- cSubHeadBg = "#000000"
- txtSizeSubHead = 14
- widthSubHead = 28
- #------------
- # GUI widgets
- h1 = Text(app, text="Hero-o-matic name builder", size=26, font="Times New Roman")
- boxForm = Box(app, width=400, height=600)
- boxForm.bg = "cyan"
- # now add widgets inside 'form' Box
- boxAdj = Box(boxForm, width="fill", height=190)
- boxAdj.bg = "#74CC9F"
- boxAdj.text_color = "#123456"
- message1 = Text(boxAdj, text="Please choose an adjective ..", width=widthSubHead )
- message1.text_color = cSubHead
- message1.bg = cSubHeadBg
- message1.text_size = txtSizeSubHead
- bgp_adjective = ButtonGroup(boxAdj, options=["Amazing", "Bonny", "Charming", "Delightful", "Vundebar"], selected="Amazing")
- #-------------
- boxColor = Box(boxForm, width="fill", height=90)
- boxColor.bg = "#54AA7F"
- boxColor.text_color = "white"
- message2 = Text(boxColor, text="Please enter a colour name ..", width=widthSubHead )
- message2.text_color = cSubHead
- message2.bg = cSubHeadBg
- message2.text_size = txtSizeSubHead
- vertSpace01 = Text(boxColor, text=" ", width="fill", size=12 )
- txt_cText = TextBox(boxColor)
- txt_cText.bg="white"
- txt_cText.text_color = "black"
- txt_cText.text_size = 18
- #-----------
- boxAni = Box(boxForm, width="fill", height=90)
- message3 = Text(boxAni, text="Please pick an animal ..", width=widthSubHead )
- message3.text_color = cSubHead
- message3.bg = cSubHeadBg
- message3.text_size = txtSizeSubHead
- vertSpace02 = Text(boxAni, text=" ", width="fill", size=12 )
- cmb_animal = Combo(boxAni, options=["Aardvark", "Badger", "Cat", "Dog", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
- cmb_animal.text_color = "#FFFFFF"
- cmb_animal.bg = "#FF0000"
- btn_make_name = PushButton(boxForm, text='Make me a hero', command= make_hero_name )
- btn_make_name.bg = "#EE66EE"
- btn_make_name.text_color = "white"
- #-----------
- boxOut = Box(boxForm, width="fill", height=90)
- lbl_output = Text(boxOut, text="A hero name will appear here", align="bottom")
- # Set up event triggers here
- # Show the GUI on the screen, start listening to events.
- txt_cText.focus()
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement