使用python第三方模块PyQy5可以非常简单方便的设计出简洁实用的界面,还可以使用 qss 对界面进一步美化。
效果展示:
完整实现代码:
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setStyleSheet("QLineEdit{border-radius:10px}"
"#Form{border-image:url(Background.jpg);}")
desktop = QtWidgets.QApplication.desktop()
Form.setFixedSize(desktop.width()//2, desktop.height()//2)
font = QtGui.QFont()
font.setPointSize(12)
Form.setFont(font)
self.frame = QtWidgets.QFrame(Form)
self.frame.setStyleSheet("QFrame{background-color:rgb(205,205,205)}"
"QFrame{border-radius:10px}")
op = QtWidgets.QGraphicsOpacityEffect()
op.setOpacity(0.5)
self.frame.setGraphicsEffect(op)
self.frame.setGeometry(QtCore.QRect(Form.width()//2, 30, Form.width()//2-30, Form.height()-60))
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.via = QtWidgets.QLabel(self.frame)
pix = QtGui.QPixmap('via.png')
self.via.setGeometry(self.frame.width()//2-100,20,200,200)
self.via.setPixmap(pix)
# self.via.setStyleSheet("border: 2px solid red")
self.via.setScaledContents(True)
self.usernameLabel = QtWidgets.QLabel(self.frame)
self.usernameLabel.setGeometry(QtCore.QRect(100, 280, 70, 30))
self.usernameLabel.setObjectName("usernameLabel")
self.usernameLabel.setFont(font)
self.usernameEdit = QtWidgets.QLineEdit(self.frame)
self.usernameEdit.setGeometry(QtCore.QRect(180, 280, 180, 30))
self.usernameEdit.setText("")
self.usernameEdit.setObjectName("usernameEdit")
self.usernameEdit.setFont(font)
self.passwordLabel = QtWidgets.QLabel(self.frame)
self.passwordLabel.setGeometry(QtCore.QRect(100, 320, 70, 30))
self.passwordLabel.setObjectName("passwordLabel")
self.passwordLabel.setFont(font)
self.passwordEdit = QtWidgets.QLineEdit(self.frame)
self.passwordEdit.setGeometry(QtCore.QRect(180, 320, 180, 30))
self.passwordEdit.setObjectName("passwordEdit")
self.passwordEdit.setEchoMode(QtWidgets.QLineEdit.Password)
# self.passwordEdit.setFont(font)
self.checkBox = QtWidgets.QCheckBox(self.frame)
self.checkBox.setGeometry(QtCore.QRect(100, 360, 220, 20))
self.checkBox.setObjectName("checkBox")
self.buttonBox = QtWidgets.QDialogButtonBox(self.frame)
self.buttonBox.setGeometry(QtCore.QRect(140, 400, 180, 30))
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setText("登录")
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setStyleSheet(
"QPushButton{color:black}"
"QPushButton:hover{color:red}"
"QPushButton{background-color:rgb(180,180,180)}"
"QPushButton{border:2px}"
"QPushButton{border-radius:10px}"
"QPushButton{padding:2px 4px}"
"QPushButton{font-size:14pt}")
self.buttonBox.button(QtWidgets.QDialogButtonBox.Close).setText("退出")
self.buttonBox.button(QtWidgets.QDialogButtonBox.Close).setStyleSheet(
"QPushButton{color:black}"
"QPushButton:hover{color:red}"
"QPushButton{background-color:rgb(180,180,180)}"
"QPushButton{border:2px}"
"QPushButton{border-radius:10px}"
"QPushButton{padding:2px 4px}"
"QPushButton{font-size:14pt}")
self.buttonBox.setObjectName("buttonBox")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.usernameLabel.setText(_translate("Form", "用户名"))
self.passwordLabel.setText(_translate("Form", "密 码"))
self.checkBox.setText(_translate("Form", "记住用户名和密码"))
if __name__=="__main__":
import sys
app=QtWidgets.QApplication(sys.argv)
widget=QtWidgets.QWidget()
ui=Ui_Form()
ui.setupUi(widget)
widget.show()
sys.exit(app.exec_())