如何将打印结果显示在对话框界面
图片: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:
f = open(fname,'r')
with f:
data = f.read()
def hex_dec(str1):
return str(int(str1.upper(),16))
a = data
b = data
c = data
d = data
e = data
f = data
g = data
h = data
i = data
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,"",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_()) teamp=f"PM2.5{hex_dec(a)}ug/m3"
self.textEdit.setText(teamp)
这样随便起个变量名,把结果以字符串形式放进去不就好了么?
页:
[1]