一、代碼展示?
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())
二、結果展示
