class MemView(tk.Frame): # memory usage def __init__(self,master,*args,**kwargs): tk.Frame.__init__(self,master,*args,**kwargs) col0 = 100 yaxis = 10 graphheight = 300 self.columnconfigure(0,minsize = col0) tk.Label(self,text = 'Memory use (total - available)').grid(row = 0,column = 2) self.lab = MemLabel(self,bd = 0) self.lab.grid(row = 1,column = 0) graphwidth = self['width'] - col0 - yaxis self.graph = ScrollGraph(self \ ,width = graphwidth, height = graphheight \ ,borderwidth = 0,highlightthickness = 0) self.graph.grid(row = 1,column = 2) self.graph.add_trace('mem',1000,0,colour = 'red') # create an X axis without ticks to show a base line XAxis(self,0,0,width = graphwidth,height = 4,bd = 0,highlightthickness = 0) \ .grid(row = 2,column = 2) # create a Y axis with ticks at 0,25,75,100 percent YAxis(self,graphheight/4,graphheight/20,height = graphheight,width = yaxis,bd = 0,highlightthickness = 0) \ .grid(row = 1,column = 1) def bump(self): x = ps.virtual_memory() mem = x.percent self.graph.scrollex('mem',0,10*mem) self.lab.percent.configure(text = str(mem) + '%') self.lab.kb.configure(text = '{0:.2f}'.format((x.total - x.available)/1048576) + ' MB') self.afterid = self.after(1000,self.bump) def start(self): self.bump() def stop(self): self.after_cancel(self.afterid) self.graph.clear()
class CpuGraph(tk.Frame): # show data for one core def __init__(self,master,*args,**kwargs): tk.Frame.__init__(self,master,*args,**kwargs) col0 = 60 xaxis = 4 yaxis = 4 graphheight = self['height'] - xaxis self.columnconfigure(0,minsize = col0) # create labels for col 0 self.lab = CpuLabel(self) self.lab.grid(column = 0,row = 0) # create graph in col 1 graphwidth = self['width'] - col0 - yaxis self.graph = ScrollGraph(self \ ,width = graphwidth, height = graphheight \ ,borderwidth = 0,highlightthickness = 0) self.graph.grid(row = 0,column = 2) # create an X axis without ticks to show a base line XAxis(self,0,0,width = graphwidth,height = xaxis,bd = 0,highlightthickness = 0) \ .grid(row = 1,column = 2) #create a Y axis without ticks YAxis(self,0,0,width = yaxis,height = graphheight,bd = 0,highlightthickness = 0) \ .grid(row = 0,column = 1) def set_sys(self,value): self.lab.sys.configure(text = value) def set_usr(self,value): self.lab.usr.configure(text = value) def clear(self): self.graph.clear()