提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

界面是根据b站up来做的链接放到文章末尾

本人菜鸡没能去除外面的form,效果图如下

文章目录


前言

环境:vc、pyton3.8.1、PYQt5


提示:以下是本篇文章正文内容,下面案例可供参考

一、环境搭建

这里不在赘述直接引用别人的博客

        一定要注意环境的配置,由于本人是菜鸡,配置了很多次(2条消息) VScode中PyQt5的简单配置(详细教程)_LGP是人间理想的博客-CSDN博客_pyqt5 vscode

二、py源码如下

1.这个是py文件

复制粘贴 后需要修改素材路径(需要修改素材路径的地方已经加上黄色背景):

from PyQt5 import QtCore, QtGui, QtWidgets

import sys , res

 

class Ui_Form(object):

    def setupUi(self, Form):

        Form.setObjectName("Form")

        Form.resize(623, 539)

        self.widget = QtWidgets.QWidget(Form)

        self.widget.setGeometry(QtCore.QRect(30, 30, 550, 500))

        self.widget.setStyleSheet("QPushButton#pushButton{\n"

" background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(120, 38, 26, 150), stop:1 rgba(255, 255, 255, 255));\n"

" color:rgba(255,255,255,220);\n"

" border-radius:5px;\n"

"}\n"

"QPushButton#pushButton:hover{\n"

" background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(120, 38, 26,150));\n"

"}\n"

"QPushButton#pushButton:pressed{\n"

" padding-left:5px;\n"

" padding-top:5px;\n"

" background-color:rgba(120,38,26,255);\n"

"}\n"

"\n"

"QPushButton#pushButton_2,#pushButton_3,#pushButton_4,#pushButton_5{\n"

"  background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(222, 190, 167,150));\n"

" color:rgba(255,255,255,220);\n"

" border-radius:5px;\n"

"}\n"

"QPushButton#pushButton_2:hover,#pushButton_3:hover,#pushButton_4:hover,#pushButton_5:hover{\n"

"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(222, 190, 167,150), stop:1 rgba(255, 255, 255, 255));\n"

"}\n"

"QPushButton#pushButton_2:pressed,#pushButton_3:pressed,#pushButton_4:pressed,#pushButton_5:pressed{\n"

" padding-left:5px;\n"

" padding-top:5px;\n"

" background-color:rgba(222,190,167,255);\n"

"}\n"

"")

        self.widget.setObjectName("widget")

        self.label = QtWidgets.QLabel(self.widget)

        self.label.setGeometry(QtCore.QRect(40, 30, 280, 430))

        self.label.setStyleSheet("border-image: url(:/images/敦煌.jpeg);\n" ”素材路径“

"border-top-left-radius:50px;")

        self.label.setText("")

        self.label.setObjectName("label")

        self.label_2 = QtWidgets.QLabel(self.widget)

        self.label_2.setGeometry(QtCore.QRect(40, 30, 280, 430))

        self.label_2.setStyleSheet("background-color:rgba(0,0,0,80);\n"

"border-top-left-radius:50px;")

        self.label_2.setText("")

        self.label_2.setObjectName("label_2")

        self.label_3 = QtWidgets.QLabel(self.widget)

        self.label_3.setGeometry(QtCore.QRect(270, 30, 240, 430))

        self.label_3.setStyleSheet("background-color:rgba(255,255,255,255);\n"

"border-bottom-right-radius:50px;")

        self.label_3.setText("")

        self.label_3.setObjectName("label_3")

        self.label_4 = QtWidgets.QLabel(self.widget)

        self.label_4.setGeometry(QtCore.QRect(340, 80, 110, 50))

        font = QtGui.QFont()

        font.setFamily("MS Gothic")

        font.setPointSize(25)

        font.setBold(True)

        font.setWeight(75)

        self.label_4.setFont(font)

        self.label_4.setStyleSheet("color:rgba(0,0,0,200);")

        self.label_4.setObjectName("label_4")

        self.lineEdit = QtWidgets.QLineEdit(self.widget)

        self.lineEdit.setGeometry(QtCore.QRect(295, 150, 190, 40))

        font = QtGui.QFont()

        font.setPointSize(12)

        self.lineEdit.setFont(font)

        self.lineEdit.setStyleSheet("background-color:rgba(0,0,0,0);\n"

"border:none;\n"

"border-bottom:2px solid rgba(120,38,26,200);\n"

"color:rgba(0,0,0,240);\n"

"padding-bottom:7px;")

        self.lineEdit.setObjectName("lineEdit")

        self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)

        self.lineEdit_2.setGeometry(QtCore.QRect(295, 215, 190, 40))

        font = QtGui.QFont()

        font.setPointSize(12)

        self.lineEdit_2.setFont(font)

        self.lineEdit_2.setStyleSheet("background-color:rgba(0,0,0,0);\n"

"border:none;\n"

"border-bottom:2px solid rgba(120,38,26,200);\n"

"color:rgba(0,0,0,240);\n"

"padding-bottom:7px;")

        self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)

        self.lineEdit_2.setObjectName("lineEdit_2")

        self.pushButton = QtWidgets.QPushButton(self.widget)

        self.pushButton.setGeometry(QtCore.QRect(295, 295, 190, 40))

        self.pushButton.setObjectName("pushButton")

        self.label_5 = QtWidgets.QLabel(self.widget)

        self.label_5.setGeometry(QtCore.QRect(290, 340, 210, 20))

        font = QtGui.QFont()

        font.setPointSize(8)

        self.label_5.setFont(font)

        self.label_5.setStyleSheet("color:rgba(0,0,0,210);\n"

"")

        self.label_5.setObjectName("label_5")

        self.horizontalLayoutWidget = QtWidgets.QWidget(self.widget)

        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(310, 370, 160, 31))

        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")

        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)

        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)

        self.horizontalLayout.setSpacing(0)

        self.horizontalLayout.setObjectName("horizontalLayout")

        self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)

        self.pushButton_2.setMaximumSize(QtCore.QSize(30, 30))

        font = QtGui.QFont()

        font.setFamily("等线")

        font.setPointSize(15)

        self.pushButton_2.setFont(font)

        self.pushButton_2.setStyleSheet("border-image: url(:/images/twitter-circle-fill.png);")

        self.pushButton_2.setText("")

        self.pushButton_2.setObjectName("pushButton_2")

        self.horizontalLayout.addWidget(self.pushButton_2)

        self.pushButton_3 = QtWidgets.QPushButton(self.horizontalLayoutWidget)

        self.pushButton_3.setMaximumSize(QtCore.QSize(30, 30))

        font = QtGui.QFont()

        font.setFamily("等线")

        font.setPointSize(15)

        self.pushButton_3.setFont(font)

        self.pushButton_3.setStyleSheet("border-image: url(:/images/facebook_facebook52.png);")

        self.pushButton_3.setText("")

        self.pushButton_3.setObjectName("pushButton_3")

        self.horizontalLayout.addWidget(self.pushButton_3)

        self.pushButton_4 = QtWidgets.QPushButton(self.horizontalLayoutWidget)

        self.pushButton_4.setMaximumSize(QtCore.QSize(30, 30))

        font = QtGui.QFont()

        font.setFamily("等线")

        font.setPointSize(15)

        self.pushButton_4.setFont(font)

        self.pushButton_4.setStyleSheet("border-image: url(:/images/微信.png);")

        self.pushButton_4.setText("")

        self.pushButton_4.setObjectName("pushButton_4")

        self.horizontalLayout.addWidget(self.pushButton_4)

        self.pushButton_5 = QtWidgets.QPushButton(self.horizontalLayoutWidget)

        self.pushButton_5.setMaximumSize(QtCore.QSize(30, 30))

        font = QtGui.QFont()

        font.setFamily("等线")

        font.setPointSize(15)

        self.pushButton_5.setFont(font)

        self.pushButton_5.setStyleSheet("border-image: url(:/images/QQ-circle-fill.png);")

        self.pushButton_5.setText("")

        self.pushButton_5.setObjectName("pushButton_5")

        self.horizontalLayout.addWidget(self.pushButton_5)

        self.retranslateUi(Form)

        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):

        _translate = QtCore.QCoreApplication.translate

        Form.setWindowTitle(_translate("Form", "Form"))

        self.label_4.setText(_translate("Form", "Log In"))

        self.lineEdit.setPlaceholderText(_translate("Form", "User Name"))

        self.lineEdit_2.setPlaceholderText(_translate("Form", "Password"))

        self.pushButton.setText(_translate("Form", "LOG In"))

        self.label_5.setText(_translate("Form", "Forgot your User Name or password?"))

if __name__ == "__main__":

    app=QtWidgets.QApplication(sys.argv)

    Form=QtWidgets.QWidget()

    ui=Ui_Form()

    ui.setupUi(Form)

    Form.show()

    sys.exit(app.exec_())


总结

b站up教程:python/PyQt5/QtDesigner设计精美登录(login)页面_哔哩哔哩_bilibili

 本人在做的时候出现过很多错误,有时候执行不了py文件,就是环境配置出了问题

我配置了这四个文件才正常执行:

 

 

 

这个是源文件好兄弟们不知道可以直接下载不,下载需要钱的话好兄弟们直接私信我,我发给好兄弟们:pyqt5制作的ui与py文件-Python文档类资源-CSDN文库