【发布时间】:2021-04-03 14:44:58
【问题描述】:
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
import pyrebase
firebaseConfig = {......}
firebase=pyrebase.initialize_app(firebaseConfig)
AUTH = firebase.auth()
class Login(QDialog):
def __init__(self):
super(Login,self).__init__()
loadUi("login.ui",self)
self.login.clicked.connect(self.loginfunction)
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.clickhere.clicked.connect(self.gotocreate)
self.invalid.setVisible(False)
def loginfunction(self):
email=self.email.text()
password=self.password.text()
try:
auth.sign_in_with_email_and_password(email,password)
except:
self.invalid.setVisible(True)
def gotocreate(self):
createacc=CreateAcc()
widget.addWidget(createacc)
widget.setCurrentIndex(widget.currentIndex()+1)
class CreateAcc(QDialog):
def __init__(self):
super(CreateAcc,self).__init__()
loadUi("createacc.ui",self)
self.confirmacc.clicked.connect(self.createaccfunction)
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirmpass.setEchoMode(QtWidgets.QLineEdit.Password)
self.invalid.setVisible(False)
def createaccfunction(self):
email = self.email.text()
if self.password.text()==self.confirmpass.text():
password=self.password.text()
try:
AUTH.create_user_with_email_and_password(email,password)
login = Login()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
except:
self.invalid.setVisible(True)
#------main-------#
app=QApplication(sys.argv)
mainwindow=Login()
widget=QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.setFixedWidth(480)
widget.setFixedHeight(620)
widget.show()
app.exec_()
使用此代码,我试图将从用户收到的信息保存到 Firebase 数据库,但我不断收到“进程已完成,退出代码 -1073740791 (0xC0000409)”错误。我决定使用异常处理,但这次“try:”块不起作用。也许我不应该使用身份验证方法来注册用户。有什么建议吗?
这里是 .ui 文件
注册界面的ui文件在下面
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(54, 54, 54);</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>180</x>
<y>50</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 28pt "MS Shell Dlg 2"; color: rgb(243, 243, 243)</string>
</property>
<property name="text">
<string>Sign up</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>40</x>
<y>170</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Email</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>270</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
<widget class="QLineEdit" name="email">
<property name="geometry">
<rect>
<x>220</x>
<y>180</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>220</x>
<y>280</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="confirmacc">
<property name="geometry">
<rect>
<x>300</x>
<y>450</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(167, 168, 167); font-size:14px</string>
</property>
<property name="text">
<string>Confirm</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>40</x>
<y>360</y>
<width>171</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Confirm Pass</string>
</property>
</widget>
<widget class="QLineEdit" name="confirmpass">
<property name="geometry">
<rect>
<x>220</x>
<y>370</y>
<width>211</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="invalid">
<property name="geometry">
<rect>
<x>310</x>
<y>420</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0)</string>
</property>
<property name="text">
<string>Invalid Email</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
登录界面在下方
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(54, 54, 54);</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>180</x>
<y>50</y>
<width>131</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 28pt "MS Shell Dlg 2"; color: rgb(243, 243, 243)</string>
</property>
<property name="text">
<string>Login </string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>40</x>
<y>170</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>270</y>
<width>141</width>
<height>61</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 15pt "MS Shell Dlg 2";
color: rgb(255, 0, 127);</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
<widget class="QLineEdit" name="email">
<property name="geometry">
<rect>
<x>200</x>
<y>180</y>
<width>201</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>200</x>
<y>280</y>
<width>201</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="login">
<property name="geometry">
<rect>
<x>300</x>
<y>430</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(167, 168, 167); font-size:14px</string>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>200</x>
<y>350</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color:rgb(255, 255, 255)</string>
</property>
<property name="text">
<string>Don't have an account? </string>
</property>
</widget>
<widget class="QPushButton" name="clickhere">
<property name="geometry">
<rect>
<x>340</x>
<y>350</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:#363636; font-size:14px; color: rgb(230, 230, 230)</string>
</property>
<property name="text">
<string>Click here!</string>
</property>
</widget>
<widget class="QLabel" name="invalid">
<property name="geometry">
<rect>
<x>310</x>
<y>400</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0)</string>
</property>
<property name="text">
<string>Invalid Login</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
【问题讨论】:
标签: python firebase pyqt pyqt5 registration