from guizero import App, PushButton def display_message(): print("Hello, World!") app = App() button = PushButton(app, text="Click me", command=display_message) app.display()
from guizero import App, PushButton, TextBox, Text def add_numbers(): num1 = int(input_box1.value) num2 = int(input_box2.value) result = num1 + num2 output_box.value = result app = App() input_box1 = TextBox(app) input_box2 = TextBox(app) button = PushButton(app, text="Add", command=add_numbers) output_box = Text(app) app.display()
from guizero import App, PushButton def change_background(): app.bg = "red" app = App() button = PushButton(app, text="Change color", command=change_background) app.display()In this example, the app's background color is changed to red when the button is clicked. The function `change_background()` simply sets the `bg` property of the app to "red". Overall, the guizero package library provides a simple and intuitive way to create GUIs in Python, and the PushButton widget is an essential tool for creating buttons that execute functions when clicked.