maroph icon

heroname2.py

maroph | PRO | 12/07/19 08:21:03 AM UTC | 0 ⭐ | 363 👁️ | Never ⏰ | []
Python |

2.21 KB

|

None

|

0 👍

/

0 👎

from guizero import App, ButtonGroup, CheckBox, Combo, info, ListBox, Picture, PushButton, Slider, Text
 
# https://lawsie.github.io/guizero/layout/\
app = App(title="Hero name generator", layout="grid")
app.bg = 'white'
app.height = 750
app.width = 400
 
 
def btn_go_clicked():
    name = "Your "
    if checkbox.value == 1:
        name += " SUPER "
    if listbox.value is not None:
        for item in listbox.value:
            name += item + " "
    name += "hero name:"
    info(name, bg_adjective.value + " " + combo_color.value + " " + combo_animal.value + " at slip level " + str(slider.value))
 
def toggle_dark_mode():
    if cb_dark.value != 0:
        app.bg = 'silver'
    else:
        app.bg = 'white'
 
 
# image: http://www.marochess.de/imgs/dntpanic.gif
picture = Picture(app, image='./dntpanic.gif', grid=[0, 0, 2, 1])
 
lbl_adjective = Text(app, text="Choose an adjective...", grid=[0,1], align="left")
bg_adjective = ButtonGroup(app, options=["Busy", "Crazy", "Crying", "Funny", "Happy", "Lazy", "Powerful"], selected="Powerful", grid=[1,1], align="left")
 
lbl_color = Text(app, text="Enter a color...", grid=[0,2], align="left")
combo_color = Combo(app, options=["Black", "Blue", "Green", "Red", "Pink", "Yellow", "Violet"], selected="Pink", grid=[1,2], align="left")
 
lbl_animal = Text(app, text="Pick an animal...", grid=[0,3], align="left")
combo_animal = Combo(app, options=["Bear", "Deer", "Hamster", "Panther", "Skunk", "Snake"], selected="Hamster", grid=[1,3], align="left")
 
lbl_slider = Text(app, text="Slip sliding away...", grid=[0,4], align="left")
slider = Slider(app, start=0, end=10, grid=[1,4], align="left")
 
# nonsense text, just added to show the functionality
lbl_listbox = Text(app, text="Extra name labeling", grid=[0,5], align="left")
listbox = ListBox(app, items=["LB1", "LB2", "LB3", "LB4"], multiselect=True, height="10", width="30", scrollbar=True, grid=[1,5], align="left")
 
 
checkbox = CheckBox(app, text="Add SUPER to hero to name", grid=[0,6], align="left")
 
cb_dark = CheckBox(app, text="Dark mode", command=toggle_dark_mode, grid=[0,7], align="left")
 
btn_go = PushButton(app, command=btn_go_clicked, text="Generate hero name", grid=[0,8, 2 ,1])
 
app.display()

Comments