from PySide2.QtWidgets import QApplication
from PySide2.QtUiTools import QUiLoader
import time
from threading import Thread
from PySide2.QtCore import Signal,QObject
class MySignals(QObject):
# 定义一种信号, 两个参数类型分别是OTextBrowser和字符串
text_print = Signal(str)
class login_pyside2():
def __init__(self):
self.ui = QUiLoader().load('pyside2_login.ui')
self.ui.loginButton.clicked.connect(self.login)
self.ms = MySignals()
self.ms.text_print.connect(self.printToGui)
def printToGui(self, text):
self.ui.loginfo.appendPlainText(str(text))
def login(self):
def therard_run():
username = self.ui.usernameEdit.text()
password = self.ui.passwordEdit.text()
for i in range(5):
logmsg = f'''成功登陆,用户名:{username},密码为{password}'''
time.sleep(1)
self.ms.text_print.emit(logmsg)
T = Thread(target=therard_run)
T.start()
if __name__ == '__main__':
app = QApplication([])
stats = login_pyside2()
stats.ui.show()
app.exec_()