File: binary_counter.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 (27 lines) | stat: -rw-r--r-- 607 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
26
27
from guizero import App, Text

number = 0
base = 2

def to_str(n,base):
    convert_string = "0123456789ABCDEF"
    if n < base:
        return convert_string[n]
    else:
        return to_str(n//base,base) + convert_string[n%base]

def counter():
    global number
    number = number + 1
    binary.value = str(to_str(number, base)).zfill(5)
    denary.value = str(number).zfill(5)

app = App()
denary = Text(app, text="00000", size=100)
binary = Text(app, text="00000", size=100)

denary.width = 10
binary.width = 10

denary.repeat(1000, counter)  # Schedule call to counter() every 1000ms
app.display()