pyside6项目,创建一个简易的账号密码输入交互界面 http://t.csdnimg.cn/sPp6l
1.关于导入自己生成的界面时,这个是要根据自己生成的login.py中的函数来定,继承的父类需找到对应所指。
# 导入我们生成的界面
from login import Ui_widget
# 导入我们生成的界面
# from login import Ui_Form
# 继承QWidget类,以获取其属性和方法
class MyWidget(QWidget,Ui_widget):
def __init__(self):
super().__init__()
# 设置界面为我们生成的界面
self.setupUi(self)
2.对于信号和槽的调用,其中调用函数加括号与否的问题:
带括号的是函数调用,直接执行函数;不带括号的是绑定事件,事件触发再执行。对于Button调用loginFuc函数,如果代码为
self.pushButton.clicked.connect(self.loginFuc):则表示为根据你执行按键按钮的触发再采集lineEdit.text,然后返回结果。
self.pushButton.clicked.connect(self.loginFuc()):则表示为直接执行loginFuc,不管你是否触发按钮,直接读取lineEdit.text,返回"no"。
# 继承QWidget类,以获取其属性和方法
class MyWidget(QWidget,Ui_widget):
def __init__(self):
super().__init__()
# 设置界面为我们生成的界面
self.setupUi(self)
self.pushButton.clicked.connect(self.loginFuc)
def loginFuc(self):
account = self.lineEdit.text()
password = self.lineEdit_2.text()
if account =='123' and password =='123':
print("yes")
else:
print("no")