From 8aa463dd80e3d87cc55e3fb953e007dd7926c09a Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Mon, 1 Oct 2018 17:12:43 -0400 Subject: [PATCH] YouTube Tutorial - Floating CPU meter --- TutorialCPUUtilization.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 TutorialCPUUtilization.py diff --git a/TutorialCPUUtilization.py b/TutorialCPUUtilization.py new file mode 100644 index 00000000..003115d7 --- /dev/null +++ b/TutorialCPUUtilization.py @@ -0,0 +1,18 @@ +import PySimpleGUI as sg +import psutil + +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(layout) + +while True: + button, values = window.ReadNonBlocking() + + if button == 'Exit' or values is None: + break + + cpu_percent = psutil.cpu_percent(interval=1) + + window.FindElement('_text_').Update(f'CPU {cpu_percent:02.0f}%')