2018-10-01 21:12:43 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
import psutil
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# Usage of PSG and cpu data
|
2018-10-01 21:12:43 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
layout = [[sg.Text('CPU Utilization')],
|
|
|
|
[sg.Text('', size=(8, 2), font='Helvetica 20',
|
|
|
|
justification='center', key='-text-')],
|
|
|
|
[sg.Exit()]]
|
|
|
|
|
|
|
|
window = sg.Window('CPU Meter', layout)
|
2018-10-01 21:12:43 +00:00
|
|
|
|
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.ReadNonBlocking()
|
2018-10-01 21:12:43 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
if event == 'Exit' or values is None:
|
2018-10-01 21:12:43 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
cpu_percent = psutil.cpu_percent(interval=1)
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window['-text-'].update(f'CPU {cpu_percent:02.0f}%')
|
|
|
|
|
|
|
|
window.close()
|