我正在python中执行一个监视进程,它指示进程使用的pid
,名称和内存。
如何使用多线程制作gui并与计算过程信息的内部方法同步
class Monitor(tk.Frame):
def __init__(self, root):
tk.Frame.__init__(self, root)
self.canvas = tk.Canvas(root, borderwidth = 0, background = "#ffffff")
self.frame = tk.Frame(self.canvas, background = "#ffffff")
self.vsb = tk.Scrollbar(root, orient = "vertical", command = self.canvas.yview)
self.canvas.configure(yscrollcommand = self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4,4), window = self.frame, anchor="nw",tags="self.frame")
self.frame.bind("<Configure>", self.onFrameConfigure)
self.tabla()
def tabla(self):
'''Put in some fake data'''
proceso = Proceso()
num_procesos = proceso.num_procesos()
tk.Label(self.frame,text = "PID",width = 8, borderwidth = 1, relief = "solid").grid(row = 0, column = 0)
tk.Label(self.frame,text = "Nombre",width = 7, borderwidth = 1, relief = "solid").grid(row = 0, column = 1)
tk.Label(self.frame,text = "Estado del proceso",width = 15, borderwidth = 1, relief = "solid").grid(row = 0, column = 2)
tk.Label(self.frame,text = "Cache",width = 7, borderwidth = 1, relief = "solid").grid(row = 0, column = 3)
tk.Label(self.frame,text = "Memoria",width = 15, borderwidth = 1, relief = "solid").grid(row = 0, column = 4)
tk.Label(self.frame,text = "Disco",width = 7, borderwidth = 1, relief = "solid").grid(row = 0, column = 5)
tk.Label(self.frame,text = "Acciones",width = 12, borderwidth = 1, relief = "solid").grid(row = 0, column = 6)
killentrada = tk.Entry(self.frame,width = 7, borderwidth = 2, relief = "solid").grid(row =1, column = 8)
killboton = tk.Button(self.frame,text = "Matar proceso", width = 10, borderwidth = 2, relief = "solid",command = proceso.kill()).grid(row = 1, column = 7)
for renglon in range(num_procesos+1):
tk.Label(self.frame, text = proceso.pid(renglon-1),borderwidth="0",relief="solid").grid(row = renglon+1, column=0)
tk.Label(self.frame, text = proceso.nombre(renglon-1)).grid(row = renglon+1, column=1)
tk.Label(self.frame, text = proceso.estado(renglon-1)).grid(row = renglon+1, column=2)
#tk.Label(self.frame, text = proceso.memoria(renglon-1)).grid(row = renglon+1, column=4)
def onFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))