上代码:
# encoding:utf-8
from PySide2.QtWidgets import QApplication,QMainWindow,QPlainTextEdit,QPushButton,\
QMessageBox
class Sats():
def __init__(self):
self.window=QMainWindow()
self.window.setWindowTitle('薪资统计')
self.window.resize(500,360)
self.window.move(400,10)
self.button=QPushButton(self.window)
self.button.move(380,80)
self.button.setText('统计')
self.button.clicked.connect(self.hande)
self.textEdit=QPlainTextEdit(self.window)
self.textEdit.setPlaceholderText('请输入薪资表格')
self.textEdit.resize(300,340)
self.textEdit.move(10,15)
def hande(self):
info=self.textEdit.toPlainText()
above_20k=''
below_20k=''
for line in info.splitlines():
if not line.strip():
continue
parts=line.split(' ')
parts=[p for p in parts if p]
name,salary,age=parts
if int(salary)>=20000:
above_20k+=name+'\n'
else:
below_20k+=name+'\n'
text=f'薪资在20k以上的:\n{above_20k} 薪资在20k以下的:\n{below_20k}'
QMessageBox.about(self.window, '薪资统计', text)
if __name__ == '__main__':
app=QApplication([])
s=Sats()
s.window.show()
app.exec_()
运行结果截图: