天天看點

linux python cpu溫度,Linux系統托盤中的Python cpu溫度

您可以通過timeout_add_seconds定義計時器,并在回調中更新托盤圖示。看看下面的例子是否适用:import gtk, gobject, os

class CPUTimer:

def __init__(self, timeout):

self.window = gtk.Window()

vbox = gtk.VBox()

self.window.add(vbox)

self.label = gtk.Label('CPU')

self.label.set_size_request(200, 40)

vbox.pack_start(self.label)

# register a timer

gobject.timeout_add_seconds(timeout, self.timer_callback)

self.window.connect("destroy", lambda w: gtk.main_quit())

self.window.connect("delete_event", lambda w, e: gtk.main_quit())

self.window.show_all()

self.timer_callback()

def timer_callback(self):

cpu_temp = os.popen('sensors | grep "temp1:" | cut -d+ -f2 | cut -c1-2').read()

print 'update CPU: ' + cpu_temp

self.label.set_text('CPU: ' + cpu_temp)

return True

if __name__ == '__main__':

timer = CPUTimer(1) # sets 1 second update interval

gtk.main()

希望這對你有幫助,謝謝