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, ListBox, Picture
- app = App(title="Hero-o-matic", width=500, height=600)
- # Function definitions for your events go here.
- def make_hero_name(): # triggered by PushButton :'Make me a hero'
- adjective = bgp_adjective.value
- colour = txt_colour.value
- animal = cmb_animal.value
- title = listbox.value
- if (title == ""):
- title = "The"
- # is Super selected ?
- if (cbSuper.value <= 0): # not checked
- honour = ""
- else:
- honour = "Super "
- hero = title + " " + honour + adjective + " " + colour + " " + animal
- lbl_output.value = "You are... " + hero + "."
- def set_dark_mode(): # if CheckBox selected, use white on black styling otherwise use colour !
- # is Dark selected ?
- if (cbDark.value <= 0): # not checked .. apply chosen colour styling
- # App ..
- app.bg = "#DDDD33"
- app.text_color = "#000000"
- h1.text_color="#CC3333" # main Heading
- # Make me a hero: PushButton
- btn_make_name.bg = "#CC3333"
- btn_make_name.text_color = "#FFFFFF"
- else: # Dark mode request
- app.bg = "#000000"
- app.text_color = "#FFFFFF"
- # -- GUI widgets .. starting with a main heading Picture & Text ------------------------
- picture = Picture(app, image="images/header_img001.png")
- h1 = Text(app, text="Hero-o-matic name builder", size=26, font="Times New Roman")
- cbDark = CheckBox(app, text="DARK mode", command= set_dark_mode )
- cbSuper = CheckBox(app, text="Super")
- messageListBox = Text(app, text="Choose a title ..")
- listbox = ListBox( app, height= 70, width= 120,items=["","Ms.","Miss","Mrs.","Mr.","Lord","Lady","Right Honourable"], scrollbar= True, selected= "")
- 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)
- 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 -------------------------------------------
- # Sizes ..
- btn_make_name.text_size = 16 # Make me a hero: PushButton
- set_dark_mode() # initial colour styling
- app.display() # Show the GUI on the screen, start listening to events.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement