用户:
企鹅不是鹅查看:0 回复:2 评论:0 创建时间:2023-08-10T12:27:28
这里使用的是QtDesigner,模板都做好了,一动算法头就大,注册窗口没法显示。
希望各位大佬指教!
五个文件(login.ui, login.py, signup.ui, signup.py, main.py)依次代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>203</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>348</width>
<height>203</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>348</width>
<height>203</height>
</size>
</property>
<property name="font">
<font>
<family>宋体</family>
</font>
</property>
<property name="windowTitle">
<string>登录</string>
</property>
<property name="toolTipDuration">
<number>-4</number>
</property>
<widget class="QPushButton" name="dl">
<property name="geometry">
<rect>
<x>20</x>
<y>140</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>登录(&L)</string>
</property>
</widget>
<widget class="QPushButton" name="tc">
<property name="geometry">
<rect>
<x>120</x>
<y>140</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>退出(&Q)</string>
</property>
</widget>
<widget class="QLabel" name="zh">
<property name="geometry">
<rect>
<x>20</x>
<y>19</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>宋体</family>
<pointsize>13</pointsize>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>账户</string>
</property>
</widget>
<widget class="QLabel" name="mm">
<property name="geometry">
<rect>
<x>20</x>
<y>95</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>宋体</family>
<pointsize>13</pointsize>
</font>
</property>
<property name="text">
<string>密码</string>
</property>
</widget>
<widget class="QLineEdit" name="zh1">
<property name="geometry">
<rect>
<x>80</x>
<y>25</y>
<width>113</width>
<height>21</height>
</rect>
</property>
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
<widget class="QLineEdit" name="mm1">
<property name="geometry">
<rect>
<x>79</x>
<y>100</y>
<width>113</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QTextBrowser" name="xx">
<property name="geometry">
<rect>
<x>210</x>
<y>20</y>
<width>121</width>
<height>101</height>
</rect>
</property>
<property name="html">
<string><!DOCTYPE H喵L PUBLIC "-//W3C//DTD H喵L 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
p, li { white-space: pre-wrap; }
hr { height: 1px; border-width: 0; }
li.unchecked::marker { content: "\2610"; }
li.checked::marker { content: "\2612"; }
</style></head><body style=" font-family:'宋体'; font-size:9pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请登录使用</p></body></html></string>
</property>
</widget>
<widget class="QPushButton" name="zc">
<property name="geometry">
<rect>
<x>220</x>
<y>140</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>注册(&I)</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>tc</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>269</x>
<y>153</y>
</hint>
<hint type="destinationlabel">
<x>293</x>
<y>192</y>
</hint>
</hints>
</connection>
</connections>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(348, 203)
Form.setMinimumSize(QtCore.QSize(348, 203))
Form.setMaximumSize(QtCore.QSize(348, 203))
font = QtGui.QFont()
font.setFamily("宋体")
Form.setFont(font)
Form.setToolTipDuration(-4)
self.dl = QtWidgets.QPushButton(Form)
self.dl.setGeometry(QtCore.QRect(20, 140, 91, 41))
self.dl.setObjectName("dl")
self.tc = QtWidgets.QPushButton(Form)
self.tc.setGeometry(QtCore.QRect(120, 140, 91, 41))
self.tc.setObjectName("tc")
self.zh = QtWidgets.QLabel(Form)
self.zh.setGeometry(QtCore.QRect(20, 19, 71, 31))
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(13)
self.zh.setFont(font)
self.zh.setLayoutDirection(QtCore.Qt.LeftToRight)
self.zh.setObjectName("zh")
self.mm = QtWidgets.QLabel(Form)
self.mm.setGeometry(QtCore.QRect(20, 95, 71, 31))
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(13)
self.mm.setFont(font)
self.mm.setObjectName("mm")
self.zh1 = QtWidgets.QLineEdit(Form)
self.zh1.setGeometry(QtCore.QRect(80, 25, 113, 21))
self.zh1.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.zh1.setPlaceholderText("")
self.zh1.setObjectName("zh1")
self.mm1 = QtWidgets.QLineEdit(Form)
self.mm1.setGeometry(QtCore.QRect(79, 100, 113, 21))
self.mm1.setObjectName("mm1")
self.xx = QtWidgets.QTextBrowser(Form)
self.xx.setGeometry(QtCore.QRect(210, 20, 121, 101))
self.xx.setObjectName("xx")
self.zc = QtWidgets.QPushButton(Form)
self.zc.setGeometry(QtCore.QRect(220, 140, 91, 41))
self.zc.setObjectName("zc")
self.retranslateUi(Form)
self.tc.clicked.connect(Form.close) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "登录"))
self.dl.setText(_translate("Form", "登录(&L)"))
self.tc.setText(_translate("Form", "退出(&Q)"))
self.zh.setText(_translate("Form", "账户"))
self.mm.setText(_translate("Form", "密码"))
self.xx.setHtml(_translate("Form", "<!DOCTYPE H喵L PUBLIC \"-//W3C//DTD H喵L 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"hr { height: 1px; border-width: 0; }\n"
"li.unchecked::marker { content: \"\\2610\"; }\n"
"li.checked::marker { content: \"\\2612\"; }\n"
"</style></head><body style=\" font-family:\'宋体\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">请登录使用</p></body></html>"))
self.zc.setText(_translate("Form", "注册(&I)"))
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>signup</class>
<widget class="QWidget" name="signup">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>188</width>
<height>130</height>
</rect>
</property>
<property name="windowTitle">
<string>注册</string>
</property>
<widget class="QLabel" name="zcyhm">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>用户名</string>
</property>
</widget>
<widget class="QLabel" name="zcmm">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>密码</string>
</property>
</widget>
<widget class="QPushButton" name="zcan">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>171</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>注册</string>
</property>
</widget>
<widget class="QLineEdit" name="zcyhm1">
<property name="geometry">
<rect>
<x>60</x>
<y>18</y>
<width>113</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="zcmm1">
<property name="geometry">
<rect>
<x>60</x>
<y>57</y>
<width>113</width>
<height>21</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'signup.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_signup(object):
def setupUi(self, signup):
signup.setObjectName("signup")
signup.resize(188, 130)
self.zcyhm = QtWidgets.QLabel(signup)
self.zcyhm.setGeometry(QtCore.QRect(10, 20, 72, 15))
self.zcyhm.setObjectName("zcyhm")
self.zcmm = QtWidgets.QLabel(signup)
self.zcmm.setGeometry(QtCore.QRect(10, 60, 72, 15))
self.zcmm.setObjectName("zcmm")
self.zcan = QtWidgets.QPushButton(signup)
self.zcan.setGeometry(QtCore.QRect(10, 90, 171, 31))
self.zcan.setObjectName("zcan")
self.zcyhm1 = QtWidgets.QLineEdit(signup)
self.zcyhm1.setGeometry(QtCore.QRect(60, 18, 113, 21))
self.zcyhm1.setObjectName("zcyhm1")
self.zcmm1 = QtWidgets.QLineEdit(signup)
self.zcmm1.setGeometry(QtCore.QRect(60, 57, 113, 21))
self.zcmm1.setObjectName("zcmm1")
self.retranslateUi(signup)
QtCore.QMetaObject.connectSlotsByName(signup)
def retranslateUi(self, signup):
_translate = QtCore.QCoreApplication.translate
signup.setWindowTitle(_translate("signup", "注册"))
self.zcyhm.setText(_translate("signup", "用户名"))
self.zcmm.setText(_translate("signup", "密码"))
self.zcan.setText(_translate("signup", "注册"))
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QMessageBox
from login import Ui_Form
class Window(QWidget, Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.retranslateUi(self)
self.message = [['sjr', '123321']]
self.dl.clicked.connect(self.denglu)
self.zc.clicked.connect(self.zhuce)
def denglu(self):
i = 0
for x in self.message:
if self.zh1.text() == x[0] and self.mm1.text() == x[1]:
self.xx.setText("登陆成功!\n账户:{0}\n密码:{1}".format(self.zh1.text(), self.mm1.text()))
i = 1
break
if i == 0:
if self.zh1.text() == '' or self.mm1.text() == '':
self.xx.setText("请将信息填写完整后重试")
else:
self.xx.setText("登陆失败!\n请重新尝试")
def zhuce(self):
QMessageBox.about(self, "还没做完", "我遇到了些技术难题,真是太尴尬了,希望大佬们教教")
if __name__ == "__main__":
app = QApplication(sys.argv)
s = Window()
s.show()
sys.exit(app.exec_())