May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our graph widget is finished, so let's head down to MainWindow and use it.
Start by creating your widget and making it the central widget:
self.graph = GraphWidget(self) self.setCentralWidget(self.graph)
Next, let's create a method that will read the current CPU usage and send it to GraphWidget. To do this, we'll need to import the cpu_percent function from the psutil library:
from psutil import cpu_percent
Now we can write our graph-updating method as follows:
def update_graph(self): cpu_usage = cpu_percent() self.graph.add_value(cpu_usage)
The cpu_percent() function returns an integer from 0 to 100, reflecting the current CPU utilization on your computer. This is perfect for sending directly to our GraphWidget, whose ...
Read now
Unlock full access