File: commands.md

package info (click to toggle)
python-guizero 1.6.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,872 kB
  • sloc: python: 7,160; makefile: 34; sh: 17
file content (35 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Commands

Widgets in guizero can be given a `command` when created, which can be used to call a function when the widget is used.

By using commands you can make your GUI change and take actions when the user interacts with it, for example by clicking a button, selecting an option or typing a message.

### Example

This code will display `hello world` when the button is pressed:

```python
from guizero import App, Text, PushButton

def say_hello():
    text.value = "hello world"

app = App()
text = Text(app)
button = PushButton(app, command=say_hello)
app.display()
```

Arguments can be passed to the command function using the `args` parameter.

```python
from guizero import App, Text, PushButton

def say_goodbye(first_name, last_name):
    text.value = first_name + " " + last_name

app = App()
text = Text(app)
button = PushButton(app, command=say_goodbye, args=['John', 'Doe'])
app.display()
```