Skip to content

Commit a893f29

Browse files
Adding explanations to the Gauge2
1 parent b7db195 commit a893f29

1 file changed

Lines changed: 42 additions & 24 deletions

File tree

examples/gauge2.py

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
11
import tkinter as tk
22
import tk_tools
33

4-
54
root = tk.Tk()
65

76
max_speed = 20000
87

8+
# Typical one-sided gauge that you might be expecting for a
9+
# speedometer or tachometer. Starts at zero and goes to
10+
# max_value when full-scale.
911
speed_gauge = tk_tools.Gauge2(root,
10-
max_value=max_speed,
11-
label='speed', unit=' m/h',bg='grey')
12+
max_value=max_speed,
13+
label='speed',
14+
unit=' m/h',
15+
bg='grey')
1216
speed_gauge.grid(row=0, column=0, sticky='news')
1317

14-
1518
tach_gauge = tk_tools.Gauge2(root,
16-
max_value=8000,
17-
label='tach', unit=' RPM',
18-
divisions=10)
19+
max_value=8000,
20+
label='tach',
21+
unit=' RPM',
22+
divisions=10)
1923
tach_gauge.grid(row=1, column=0, sticky='news')
2024

2125
strange_gauge = tk_tools.Gauge2(root,
22-
max_value=30000,
23-
label='strange', unit=' blah',
24-
divisions=10, red=90, yellow=60)
26+
max_value=30000,
27+
label='strange', unit=' blah',
28+
divisions=10, red=90, yellow=60)
2529
strange_gauge.grid(row=2, column=0, sticky='news')
2630

27-
batV_gauge = tk_tools.Gauge2(root, height=120, width=250,
28-
max_value=16, min_value=8,
29-
label='Bat voltage', unit='V',
30-
divisions=8, yellow=60, red=75,
31-
red_low=30, yellow_low=40)
31+
# The battery voltage gauge has a lower voltage limit and an
32+
# upper voltage limit. These are automatically created when
33+
# one imposes values on red_low and yellow_low along with
34+
# using the min_value.
35+
batV_gauge = tk_tools.Gauge2(root, height=120, width=250,
36+
max_value=16, min_value=8,
37+
label='Bat voltage',
38+
unit='V',
39+
divisions=8,
40+
yellow=60,
41+
red=75,
42+
red_low=30,
43+
yellow_low=40)
3244
batV_gauge.grid(row=0, column=1, sticky='news')
3345

34-
batI_gauge = tk_tools.Gauge2(root, height=120, width=250,
35-
max_value=6, min_value=-8,
36-
label='Bat current', unit='A',
37-
divisions=14, yellow=80, red=90,
38-
red_low=20, yellow_low=30,bg='lavender')
46+
# Similar to the previous gauge with bi-directional, but shows an
47+
# imbalanced configuration along with support for negative numbers.
48+
batI_gauge = tk_tools.Gauge2(root, height=120, width=250,
49+
max_value=6,
50+
min_value=-8,
51+
label='Bat current', unit='A',
52+
divisions=14, yellow=80, red=90,
53+
red_low=20, yellow_low=30, bg='lavender')
3954
batI_gauge.grid(row=1, column=1, sticky='news')
4055

56+
# initialization of some variables.
4157
count = 0
4258
up = True
4359

@@ -57,15 +73,17 @@ def update_gauge():
5773
if count <= 0.0:
5874
up = True
5975

76+
# update the gauges according to their value
6077
speed_gauge.set_value(count)
6178
tach_gauge.set_value(count)
6279
strange_gauge.set_value(count)
63-
batV_gauge.set_value(count/1000)
64-
batI_gauge.set_value((count-10000)/1000)
80+
batV_gauge.set_value(count / 1000)
81+
batI_gauge.set_value((count - 10000) / 1000)
6582

6683
root.after(50, update_gauge)
6784

6885

69-
root.after(100, update_gauge)
86+
if __name__ == '__main__':
87+
root.after(100, update_gauge)
7088

71-
root.mainloop()
89+
root.mainloop()

0 commit comments

Comments
 (0)