File: auto_update_example.py

package info (click to toggle)
python-guizero 1.1.1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,676 kB
  • sloc: python: 6,286; makefile: 28; sh: 17
file content (25 lines) | stat: -rw-r--r-- 511 bytes parent folder | download | duplicates (4)
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
from guizero import *
import random


def read_sensor():
    return random.randrange(3200, 5310, 10) / 100


def update_label():
    text.value = read_sensor()
    # recursive call
    text.after(1000, update_label)


if __name__ == '__main__':
    app = App(title='Sensor Display!',
              height=100,
              width=200,
              layout='grid')

    title = Text(app, 'Sensor value:', grid=[0, 0])
    text = Text(app, "xx", grid=[1, 0])

    text.after(1000, update_label)
    app.display()