from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit,QMessageBox
classfirst_example:def__init__(self):
self.window = QMainWindow()
self.window.move(300,180)#窗口位置
self.window.resize(400,400)#大小
self.text = QPlainTextEdit(self.window)
self.text.move(10,30)
self.text.resize(180,300)
self.button = QPushButton('统计',self.window)
self.button.move(250,50)
self.button.resize(30,30)
self.button.clicked.connect(self.calculate)#button回调函数,术语也叫为signal,所回调的函数叫slotdefcalculate(self):
info = self.text.toPlainText()#获取对象text中的字符文本
over_20000 =""
below_20000 =""for line in info.splitlines():#获取每行ifnot line.strip():#记得加判断是否为空continue
parts = line.split(' ')
parts =[p for p in parts if p]
name,salary,age = parts
ifint(salary)<=20000:
below_20000 += name +'\n'else:
over_20000 += name +'\n'
QMessageBox.about(self.window,'统计结果',f'薪资20000以下的有:\n{below_20000}\n\n薪资20000以上的有:\n{over_20000}')#弹出消息窗口
app = QApplication([])
example = first_example()
example.window.show()
app.exec_()
from Main import get_result
from PySide2.QtWidgets import QApplication
from PySide2.QtUiTools import QUiLoader
classStats:def__init__(self):
self.ui = QUiLoader().load('windows.ui')
self.ui.button.clicked.connect(self.return_info)defreturn_info(self):
username = self.ui.number_input.toPlainText()
userpassword = self.ui.password_input.toPlainText()
a = get_result(username, userpassword)
self.ui.info_window.setText(str(a))
app = QApplication([])
main = Stats()
main.ui.show()
app.exec_()