Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This Python code is a demo of the GUI guizero (with PushButton trigger)
- # guizero works with tkinter but simpler with extra widgets eg. Slider
- # https://lawsie.github.io/guizero/slider/
- # guizero - Hero name generator
- from guizero import App, Text, CheckBox, Combo, PushButton, TextBox
- app = App(title="Hero-o-matic")
- # Function definitions for your events go here.
- def make_hero_name():
- adjective = bgp_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- if (cbSuper.value <= 0): # not checked
- honour = ""
- else:
- honour = "Super "
- hero = honour + adjective + " " + colour + " " + animal
- lbl_output.value = "You are... The " + hero + "."
- # -- GUI widgets .. starting with a main heading Text ------------------------
- h1 = Text(app, text="Hero-o-matic generator", size=26, color="#CC3333", font="Times New Roman")
- message1 = Text(app, text="Choose an adjective")
- bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful", "Vundebar"], selected="Amazing", width=20)
- message2 = Text(app, text="Enter a colour?")
- txt_colour = TextBox(app)
- message3 = Text(app, text="Pick an animal")
- cmb_animal = Combo(app, options=["Aardvark", "Badger", "Cat", "Dog", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
- cbSuper = CheckBox(app, text="Super")
- btn_make_name = PushButton(app, text='Make me a hero', command= make_hero_name ) # event handler linked here
- lbl_output = Text(app, text="A hero name will appear here")
- # -- Set STYLING & other properties -------------------------------------------
- # App ..
- app.bg = "#DDDD33"
- # Make me a hero: PushButton
- btn_make_name.text_size = 16
- btn_make_name.bg = "#CC3333"
- btn_make_name.text_color = "#FFFFFF"
- # Set up event triggers here ?
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement