一、代码展示
import sysfrom PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QWidget, QApplication, QLabel, QLineEdit, QPushButton
from PyQt6 import uic
from PyQt6.QtCore import Qt# 封装一个我的窗口类
class MyWidget(QWidget):def __init__(self):super().__init__()# 通过uic将ui界面加载到程序中来uic.loadUi("./qq.ui",self)#设置窗口标题self.setWindowTitle("QQ")#固定窗口大小self.setFixedSize(324,430)#调整窗口颜色并将四角圆化self.setStyleSheet("background-color:white,border-radius:10px")#去掉头部窗口# self.setWindowFlag(Qt.WindowType.FramelessWindowHint)#静态加载ui界面上的qqlabel组件self.qqlabel = self.findChild(QLabel,'qqlabel')#重新设置qqlabel的尺寸大小self.qqlabel.resize(80,80)#移动qqlabelself.qqlabel.move(130,61)#设置qqlabel的图片self.qqlabel.setPixmap(QPixmap("pictrue/qq.png"))#自动适应self.qqlabel.setScaledContents(True)#底色为白色,设置为圆形样式self.qqlabel.setStyleSheet("background-color:white,border-radius:50%")#静态加载ui界面上的qqnumber组件self.qqnumber = self.findChild(QLineEdit,'qqnumber')#设置占位信息self.qqnumber.setPlaceholderText("输入QQ号")#设置底色白色self.qqnumber.setStyleSheet("background-color:white")# 静态加载ui界面上的password组件self.password = self.findChild(QLineEdit,"password")#设置占位信息self.password.setPlaceholderText("输入QQ密码")#设置底色self.password.setStyleSheet("background-color:white")#设置输入字段为密码回响self.password.setEchoMode(QLineEdit.EchoMode.Password)# 静态加载ui界面上的pushButton组件self.pushButton = self.findChild(QPushButton,'pushButton')if __name__ == '__main__':#用应用程序类QApplication实例化appapp = QApplication(sys.argv)#用上面的窗口类实例化myWidgetmyWidget = MyWidget()#显示窗口myWidget.show()#让应用程序进入消息循环sys.exit(app.exec())
二、结果展示
