Advertisement
JDpaste

Python code: GUI guizero demo PushButton

Sep 23rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. # This Python code is a basic 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. # eventgui.py
  5. # 2 buttons .. 2 actions. Read text fields and open alert-type info box <OK>
  6.  
  7. # Import .. GUI widgets etc
  8. from guizero import App, TextBox, PushButton, Text, info
  9. import math
  10.  
  11. app = App( title="Synopsis of You ++", bg = "#FFFF00", height = 400, width = 600 )
  12.  
  13. # Event Handler functions ------------------
  14. def btn_go_clicked():  # on PushButton click -> get values from TextBox(es)
  15.     likeAnimal = txtAnimal.value
  16.     if (likeAnimal == ""):
  17.         appendStr = ", please tell me more .."
  18.     else:
  19.         appendStr = " .. you like " + likeAnimal
  20.    
  21.     info("Greetings","Hello " + txt_name.value + appendStr)
  22.  
  23. def btn_alt_clicked():
  24.     #info("Maths Fact","PI is " + "3.1416 to 4 dp.")
  25.     outStr = "PI is {0:.5f}".format(math.pi) # format float into a string
  26.     info("Maths Fact", outStr)
  27.  
  28. # GUI widgets -----------
  29. lbl_name = Text(app, text="Hello. What's your name?", color="red", size=22)
  30. txt_name = TextBox(app, width=50)
  31.  
  32. lblAnimal = Text(app, text="Please name an animal that you like ?")
  33. txtAnimal = TextBox(app, width=40)
  34.  
  35. btn_go   = PushButton(app, command=btn_go_clicked, text="Synopsis ..", padx=8,pady=7)
  36. btn_fact = PushButton(app, command=btn_alt_clicked, text="Maths fact ..", padx=8,pady=7)
  37.  
  38. # change parameters of widgets
  39. btn_go.bg   ="#33FF55"
  40. btn_fact.bg ="#33FFAA"
  41. # Show the GUI on the screen
  42. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement