-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathDemo_Desktop_Widget_CPU_Utilization_Simple.py
41 lines (31 loc) · 1.25 KB
/
Demo_Desktop_Widget_CPU_Utilization_Simple.py
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
#!/usr/bin/env python
import FreeSimpleGUI as sg
import psutil
# Yet another usage of CPU data
# ---------------- Create Form ----------------
sg.theme('Black')
layout = [[sg.Text('CPU Utilization')],
[sg.Text('', size=(8, 2), font=('Helvetica', 20),
justification='center', key='-text-')],
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0), size=(9, 1)),
sg.Spin([x + 1 for x in range(10)], 3, key='-spin-')]]
# Layout the rows of the Window
window = sg.Window('CPU Meter',
layout,
no_titlebar=True,
keep_on_top=True,
grab_anywhere=True, finalize=True)
# ---------------- main loop ----------------
interval = 10 # For the first one, make it quick
while True:
# --------- Read and update window --------
event, values = window.read(timeout=interval)
# --------- Do Button Operations --------
if event in (sg.WIN_CLOSED, 'Exit'):
break
interval = int(values['-spin-'])*1000
cpu_percent = psutil.cpu_percent(interval=1)
# --------- Display timer in window --------
window['-text-'].update(f'CPU {cpu_percent:02.0f}%')
# Broke out of main loop. Close the window.
window.close()