Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

python - How do you update titles using RUMPS?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...