我使用pyqt5,qt desinger制作了显示CPU,RAM,其他的工具,您可以在下面看到此链接。
CPU名称:
但是当我使用导入wmi和从win32com.client导入GetObject将(CPU名称)加在一起(CPU温度)时遇到问题 请帮助我如何运行togerther?
import psutil
import sys
import time
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import pyqtSignal
import ToolComputer
class MainUIClass(QtWidgets.QMainWindow,ToolComputer.Ui_MainWindow):
def __init__(self,parent=None):
super(MainUIClass,self).__init__(parent)
self.setupUi(self)
## Thread Process ####
self.threadclassProcess = ThreadClassPROCESS01()
self.threadclassProcess.start()
self.threadclassProcess.ProcessList01.connect(self.ProcessList01)
## Thread Temperature ####
self.threadclassTem = ThreadClassTEM()
self.threadclassTem.start()
self.threadclassTem.TEMPLcdNumber.connect(self.TEMPLcdNumber)
def TEMPLcdNumber(self,temp):
self.CPUTEMP_LCD.display(temp)
def ProcessList01(self,pro1):
self.Name_TXT.append(pro1)
class ThreadClassTEM(QtCore.QThread):
TEMPLcdNumber = pyqtSignal(float)
def __init__(self, parent=None):
super(ThreadClassTEM,self).__init__(parent)
def run(self):
**import wmi**
while True:
w = wmi.WMI(namespace="root\\wmi")
temp = w.MSAcpi_ThermalZoneTemperature()[0].CurrentTemperature / 10.0 - 273.15
time.sleep(1)
self.TEMPLcdNumber.emit(temp)
time.sleep(1)
class ThreadClassPROCESS01(QtCore.QThread):
ProcessList01 = pyqtSignal(str)
def __init__(self, parent=None):
super(ThreadClassPROCESS01,self).__init__(parent)
def run(self):
**from win32com.client import GetObject**
root_winmgmts = GetObject("winmgmts:root\cimv2")
cpus = root_winmgmts.ExecQuery("Select * from Win32_Processor")
pro1 = str(cpus[0].Name)
time.sleep(1)
self.ProcessList01.emit(pro1)
if __name__ == "__main__":
a = QtWidgets.QApplication(sys.argv)
app = MainUIClass()
app.show()
a.exec_()
错误调试:
C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\pythonw.exe "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py" --multiproc --client 127.0.0.1 --port 61865 --file "D:/Document/Python/Tool Computer Update 01/GetOtheInfor11111.py"
pydev debugger: process 6112 is connecting
Connected to pydev debugger (build 129.782)
Traceback (most recent call last):
File "D:/Document/Python/Tool Computer Update 01/GetOtheInfor11111.py", line 52, in run
import wmi
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wmi.py", line 157, in <module>
obj = GetObject ("winmgmts:")
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\client\__init__.py", line 72, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\client\__init__.py", line 87, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None)
Error in sys.excepthook:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd_breakpoints.py", line 122, in excepthook
thread.additionalInfo.exception = (exctype, value, tb)
AttributeError: '_DummyThread' object has no attribute 'additionalInfo'
Original exception was:
Traceback (most recent call last):
File "D:/Document/Python/Tool Computer Update 01/GetOtheInfor11111.py", line 52, in run
import wmi
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wmi.py", line 157, in <module>
obj = GetObject ("winmgmts:")
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\client\__init__.py", line 72, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Users\Thinkpad\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\client\__init__.py", line 87, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None)
请帮助我,我无法一起运行2类CPU温度和CPU名称