Advertisement
JDpaste

Python GUI guizero: CheckBox and Combo

Sep 24th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. # This Python code is a demo of the GUI guizero (with PushButton trigger)
  2. # guizero works with tkinter but simpler with extra widgets eg. Slider
  3. # https://lawsie.github.io/guizero/slider/
  4. # guizero - Hero name generator
  5. from guizero import App, Text, CheckBox, Combo, PushButton, TextBox
  6. app = App(title="Hero-o-matic")
  7.  
  8. # Function definitions for your events go here.
  9. def make_hero_name():
  10.     adjective = bgp_adjective.value
  11.     colour = txt_colour.value
  12.     animal = cmb_animal.value
  13.     if (cbSuper.value <= 0): # not checked
  14.         honour = ""
  15.     else:
  16.         honour = "Super "
  17.    
  18.     hero = honour + adjective + " " + colour + " " + animal
  19.     lbl_output.value = "You are... The " + hero + "."
  20.  
  21. # -- GUI widgets .. starting with a main heading Text ------------------------
  22. h1 = Text(app, text="Hero-o-matic generator", size=26, color="#CC3333", font="Times New Roman")
  23.  
  24. message1 = Text(app, text="Choose an adjective")
  25. bgp_adjective = Combo(app, options=["Amazing", "Bonny", "Charming", "Delightful", "Vundebar"], selected="Amazing", width=20)
  26.  
  27. message2 = Text(app, text="Enter a colour?")
  28. txt_colour = TextBox(app)
  29.  
  30. message3 = Text(app, text="Pick an animal")
  31. cmb_animal = Combo(app, options=["Aardvark", "Badger", "Cat", "Dog", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
  32.  
  33. cbSuper = CheckBox(app, text="Super")
  34.  
  35. btn_make_name = PushButton(app, text='Make me a hero', command= make_hero_name ) # event handler linked here
  36. lbl_output = Text(app, text="A hero name will appear here")
  37.  
  38. # -- Set STYLING & other properties -------------------------------------------
  39. # App ..
  40. app.bg = "#DDDD33"
  41. # Make me a hero: PushButton
  42. btn_make_name.text_size = 16
  43. btn_make_name.bg = "#CC3333"
  44. btn_make_name.text_color = "#FFFFFF"
  45.  
  46. # Set up event triggers here ?
  47.  
  48. # Show the GUI on the screen, start listening to events.
  49. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement