PySimpleGUI/DemoPrograms/TutorialCPUUtilization.py

24 lines
525 B
Python
Raw Normal View History

2018-10-01 21:12:43 +00:00
import PySimpleGUI as sg
import psutil
# Usage of PSG and cpu data
2018-10-01 21:12:43 +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:
event, values = window.ReadNonBlocking()
2018-10-01 21:12:43 +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)
window['-text-'].update(f'CPU {cpu_percent:02.0f}%')
window.close()