-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathDemo_LED_Indicators.py
More file actions
51 lines (39 loc) · 1.69 KB
/
Demo_LED_Indicators.py
File metadata and controls
51 lines (39 loc) · 1.69 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import PySimpleGUI as sg
import time
import random
"""
Demo program showing how to create your own "LED Indicators"
The LEDIndicator function acts like a new Element that is directly placed in a window's layout
After the Window is created, use the SetLED function to access the LED and set the color
Copyright 2018-2026 PySimpleGUI. All rights reserved.
"""
def LEDIndicator(key=None, radius=30):
return sg.Graph(canvas_size=(radius, radius),
graph_bottom_left=(-radius, -radius),
graph_top_right=(radius, radius),
pad=(0, 0), key=key)
def SetLED(window, key, color):
graph = window[key]
graph.erase()
graph.draw_circle((0, 0), 12, fill_color=color, line_color=color)
layout = [[sg.Text('My LED Status Indicators', size=(20,1))],
[sg.Text('CPU Use'), LEDIndicator('_cpu_')],
[sg.Text('RAM'), LEDIndicator('_ram_')],
[sg.Text('Temperature'), LEDIndicator('_temp_')],
[sg.Text('Server 1'), LEDIndicator('_server1_')],
[sg.Button('Exit')]]
window = sg.Window('My new window', layout, default_element_size=(12, 1), auto_size_text=False, finalize=True)
i = 0
while True: # Event Loop
event, value = window.read(timeout=400)
if event == 'Exit' or event == sg.WIN_CLOSED:
break
if value is None:
break
i += 1
SetLED(window, '_cpu_', 'green' if random.randint(1, 10) > 5 else 'red')
SetLED(window, '_ram_', 'green' if random.randint(1, 10) > 5 else 'red')
SetLED(window, '_temp_', 'green' if random.randint(1, 10) > 5 else 'red')
SetLED(window, '_server1_', 'green' if random.randint(1, 10) > 5 else 'red')
window.close()