|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
图片:https://imgchr.com/i/wCK1oD
源代码如下:
from PyQt5.QtWidgets import (QMainWindow,QTextEdit,QAction,QFileDialog,QApplication)
from PyQt5.QtGui import *
import sys
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.textEdit = QTextEdit()
self.setCentralWidget(self.textEdit)
self.statusBar()
openFile = QAction(QIcon('open.png'),'打开文件',self)
openFile.setShortcut('Ctrl+A')
openFile.setStatusTip('选择数据')
openFile.triggered.connect(self.showDialog)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&打开文件')
fileMenu.addAction(openFile)
self.setGeometry(500,230,500,220)
self.setWindowTitle('温湿度传感器参数')
self.show()
def showDialog(self):
fname = QFileDialog.getOpenFileName(self,'Open file','/home')
if fname[0]:
f = open(fname[0],'r')
with f:
data = f.read()
def hex_dec(str1):
return str(int(str1.upper(),16))
a = data[31:39]
b = data[40:48]
c = data[49:56]
d = data[57:64]
e = data[65:72]
f = data[73:80]
g = data[81:88]
h = data[89:96]
i = data[97:104]
temp = {'0':'东北偏北','1':'东北','2':'东北偏东','3':'正东','4':'东南偏东','5':'东南','6':'东南偏南','7':'正南','8':'西南偏南','9':'西南','10':'西南偏西','11':'正西','12':'西北偏西','13':'西北','14':'西北偏北','15':'正北'}
print ("PM2.5 ",hex_dec(a),"ug/m3",sep="")
print ("PM10 ",hex_dec(b),"ug/m3",sep="")
print ("噪声 ",hex_dec(c),"dB",sep="")
print ("温度 ",hex_dec(d),"℃",sep="")
print ("湿度 ",hex_dec(e),"%RH",sep="")
#print ("风向",hex_dec(f),"",sep="")
print ("风向 ",temp[hex_dec(f)],"",sep="")
print ("风速 ",hex_dec(g),"m/s",sep="")
print ("Tsp ",hex_dec(h),"ug/m3",sep="")
print ("大气压 ",hex_dec(i),"mbar",sep="")
#A = 'print ("PM2.5 ",hex_dec(a),"ug/m3",sep="")'
#eval(A)
self.textEdit.setText(data)
if __name__=='__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) |
|