Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This Python code is a basic 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/
- # eventgui.py
- # 2 buttons .. 2 actions. Read text fields and open alert-type info box <OK>
- # Import .. GUI widgets etc
- from guizero import App, TextBox, PushButton, Text, info
- import math
- app = App( title="Synopsis of You ++", bg = "#FFFF00", height = 400, width = 600 )
- # Event Handler functions ------------------
- def btn_go_clicked(): # on PushButton click -> get values from TextBox(es)
- likeAnimal = txtAnimal.value
- if (likeAnimal == ""):
- appendStr = ", please tell me more .."
- else:
- appendStr = " .. you like " + likeAnimal
- info("Greetings","Hello " + txt_name.value + appendStr)
- def btn_alt_clicked():
- #info("Maths Fact","PI is " + "3.1416 to 4 dp.")
- outStr = "PI is {0:.5f}".format(math.pi) # format float into a string
- info("Maths Fact", outStr)
- # GUI widgets -----------
- lbl_name = Text(app, text="Hello. What's your name?", color="red", size=22)
- txt_name = TextBox(app, width=50)
- lblAnimal = Text(app, text="Please name an animal that you like ?")
- txtAnimal = TextBox(app, width=40)
- btn_go = PushButton(app, command=btn_go_clicked, text="Synopsis ..", padx=8,pady=7)
- btn_fact = PushButton(app, command=btn_alt_clicked, text="Maths fact ..", padx=8,pady=7)
- # change parameters of widgets
- btn_go.bg ="#33FF55"
- btn_fact.bg ="#33FFAA"
- # Show the GUI on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement