I am trying to create an app that shows CPU usage. However, I can't really find the solution to update the CPU usage as it only shows the CPU percentage of the CPU usage when you run the program. What should I do?
import psutil
import rumps
def get_cpu_usage():
run = True
if run is True:
return psutil.cpu_percent(interval=0.5)
class application(object):
def __init__(self):
self.app = rumps.App("CPUchecker")
self.interval = 1200
self.bar_menu()
self.stophur = rumps.MenuItem(title=get_cpu_usage())
self.menu = ["updating"]
@rumps.timer(1)
def bar_menu(self):
run = True
if run is True:
get_cpu_usage()
self.app.title = "CPU: {}%".format(get_cpu_usage())
def run(self):
self.app.run()
if __name__ == '__main__':
app = application()
app.run()
I tried looking at this question but it didn't really help with my problem
question from:
https://stackoverflow.com/questions/65837839/how-do-you-update-titles-using-rumps 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…