PyQt的窗口,按钮,行编辑器,标签

一、窗口

python 复制代码
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QWidget
import sys

from PyQt6.QtCore import Qt
class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        # 设置窗口标题
        self.setWindowTitle('QQ')

        #设置窗口图标
        self.setWindowIcon(QIcon(r"C:\Users\25026\Desktop\picture\qq.png"))# 导入QIcon

        # 设置背景颜色
        self.setStyleSheet("background-color:rgb(0,255,0)")

        #重新设置大小
        self.resize(200,100)

        # 锁定窗口大小
        self.setFixedSize(200,100)

        # 设置纯净窗口
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint) # 导入Qt




if __name__=='__main__':
    app=QApplication(sys.argv)

    myWidget=MyWidget()

    myWidget.show()

    sys.exit(app.exec())

二、按钮

python 复制代码
import sys

from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton


#封装我的窗口类
class MyWidget(QWidget):
    #构造函数
    def __init__(self):
        #初始化父类
        super().__init__()

        self.resize(600,400)

        #创建第一个按钮
        btn1 = QPushButton()  #无参构造
        #btn1.show(),只会让组件独立显示
        #如果想让组件依赖于窗口显示  则需要给组件设置父组件(父对象)
        btn1.setParent(self)
        #设置文本
        btn1.setText("第一个按钮")
        #设置背景颜色
        btn1.setStyleSheet("background-color:green")


        #创建第二个按钮
        btn2 = QPushButton("第二个按钮",self)
        #移动
        btn2.move(100,200)
        #设置图标
        btn2.setIcon(QIcon("C:\\Users\\admin\\Desktop\\recent\\pictrue\\pictrue\\qq.png"))

        #创建第三个按钮
        btn3 = QPushButton(QIcon("C:\\Users\\admin\\Desktop\\recent\\pictrue\\pictrue\\qq.png"),"第三个按钮",self)
        btn3.move(200,150)
        btn3.resize(140,200)
        #设置按钮是否可用
        btn3.setEnabled(False) #不可用



if __name__ == "__main__":
    app = QApplication(sys.argv)

    myWidget = MyWidget()

    myWidget.show()

    sys.exit(app.exec())

三、行编辑器

python 复制代码
import sys

from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QWidget, QLineEdit


#封装我的窗口类
class MyWidget(QWidget):
    #构造函数
    def __init__(self):
        #初始化父类
        super().__init__()

        self.resize(600,400)

        #创建第一个行编辑器
        edit1 = QLineEdit()
        edit1.setParent(self)
        edit1.resize(200,50)

        #创建第二个行编辑器
        edit2 = QLineEdit(self)
        edit2.move(300,200)
        #回显模式的设置
        edit2.setEchoMode(QLineEdit.EchoMode.Password)

        #创建第三个行编辑器
        edit3 = QLineEdit("张三",self) #默认文本
        edit3.move(400,300)

        #创建第四个行编辑器
        edit4 = QLineEdit(self)
        edit4.move(500,400)
        #设置占位
        edit4.setPlaceholderText("手机号/QQ号码/邮箱")








if __name__ == "__main__":
    app = QApplication(sys.argv)

    myWidget = MyWidget()

    myWidget.show()

    sys.exit(app.exec())

四、标签

python 复制代码
import sys

from PyQt6.QtGui import QIcon, QPixmap, QMovie
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton


#封装我的窗口类
class MyWidget(QWidget):
    #构造函数
    def __init__(self):
        #初始化父类
        super().__init__()

        self.resize(600,400)

        #创建第一个标签
        lab1 = QLabel()
        lab1.setParent(self)
        lab1.resize(100,100)
        lab1.move(300,300)
        lab1.setStyleSheet("background-color:green")

        # 创建第二个标签
        lab2 = QLabel("我是一个标签",self)
        lab2.resize(100, 100)
        lab2.move(500, 300)

        # 创建第三个标签
        lab3 = QLabel(self)
        lab3.resize(300, 100)
        lab3.move(200, 200)
        #设置图片
        lab3.setPixmap(QPixmap("C:\\Users\\admin\\Desktop\\recent\\pictrue\\pictrue\\logo.png"))
        #设置自动适应
        lab3.setScaledContents(True)

        #创建第四个标签
        lab4 = QLabel(self)
        lab4.resize(600,200)
        lab4.setStyleSheet("background-color:green")
        #实例化一个动图对象  动图类 QMovie
        mv = QMovie("C:\\Users\\admin\\Desktop\\recent\\pictrue\\pictrue\\zz.gif")
        #将动图设置到标签中
        lab4.setMovie(mv)
        #让动图动起来
        mv.start()
        #自动适应
        lab4.setScaledContents(True)

        #按钮类
        btn1 = QPushButton("登录",self)
        btn1.move(100,500)
        btn1.resize(80,30)
        btn1.setStyleSheet("background-color:green;border-radius:3px;color:white")

五、一个简单的登录页面

python 复制代码
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton
import sys
from PyQt6.QtGui import QIcon, QPixmap, QMovie

class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        # 窗口设置
        self.setWindowTitle('登录页面')
        self.resize(800,600)
        self.setFixedSize(800,600)
        self.setWindowIcon(QIcon(r"C:\Users\25026\Desktop\photos\vip.png"))

        #背景动态图
        bgi_lab=QLabel(self)
        bgi_lab.resize(800,600)

        mv=QMovie(r"C:\Users\25026\Desktop\photos\starry.gif")
        bgi_lab.setMovie(mv)
        mv.start()
        bgi_lab.setScaledContents(True)

        # 两边动图
        lab_l = QLabel(self)
        lab_l.resize(150, 200)
        lab_l.move(50, 200)
        mvl = QMovie(r"C:\Users\25026\Desktop\photos\door.gif")
        lab_l.setMovie(mvl)
        mvl.start()
        lab_l.setScaledContents(True)

        lab_r = QLabel(self)
        lab_r.resize(150, 200)
        lab_r.move(600, 200)
        mvr = QMovie(r"C:\Users\25026\Desktop\photos\door.gif")
        lab_r.setMovie(mvr)
        mvr.start()
        lab_r.setScaledContents(True)

        #头像
        lab_head=QLabel(self)
        lab_head.resize(150,150)
        lab_head.move(320,100)
        lab_head.setPixmap(QPixmap(r"C:\Users\25026\Desktop\photos\mm.png"))
        lab_head.setScaledContents(True)

        # 登录
        edit_id=QLineEdit(self)
        edit_id.resize(200, 30)
        edit_id.move(300,300)
        edit_id.setPlaceholderText('账户名')
        edit_id.setStyleSheet('background-color:rgba(169, 169, 169,0.8);border: none;border-radius:2px')

        edit_pwd = QLineEdit(self)
        edit_pwd.resize(200, 30)
        edit_pwd.move(300, 350)
        edit_pwd.setPlaceholderText('密码')
        edit_pwd.setEchoMode(QLineEdit.EchoMode.Password)
        edit_pwd.setStyleSheet('background-color:rgba(169, 169, 169,0.8);border: none;border-radius:2px')

        #登录按钮
        btn1=QPushButton(QIcon(r"C:\Users\25026\Desktop\photos\login-guidelines.png"),'登录',self)
        btn1.resize(200,60)
        btn1.move(300, 400)
        btn1.setStyleSheet('background-color:rgb(128, 128, 128);border-radius:10px')

        # 账户密码的图标
        lab_id=QLabel(self)
        lab_id.resize(30,30)
        lab_id.move(270,300)
        lab_id.setPixmap(QPixmap(r"C:\Users\25026\Desktop\photos\pnone.png"))
        lab_id.setScaledContents(True)

        lab_pwd = QLabel(self)
        lab_pwd.resize(30, 30)
        lab_pwd.move(270, 350)
        lab_pwd.setPixmap(QPixmap(r"C:\Users\25026\Desktop\photos\lock.png"))
        lab_pwd.setScaledContents(True)





if __name__=='__main__':
    app=QApplication(sys.argv)

    myWidget=MyWidget()

    myWidget.show()

    sys.exit(app.exec())
相关推荐
Tapdata40 分钟前
全球 DaaS 市场研究报告上线,聚焦数据服务化趋势与行业演进路径
数据库
李少兄2 小时前
MySQL 默认连接数
数据库·mysql
刘一说2 小时前
资深Java工程师的面试题目(六)数据存储
java·开发语言·数据库·面试·性能优化
江沉晚呤时2 小时前
EventSourcing.NetCore:基于事件溯源模式的 .NET Core 库
java·开发语言·数据库
C++ 老炮儿的技术栈2 小时前
VSCode -配置为中文界面
大数据·c语言·c++·ide·vscode·算法·编辑器
珹洺3 小时前
数据库系统概论(十九)详细讲解关系查询处理与查询优化
数据库
liulun3 小时前
SQLite官方数据库加密方案
数据库·sqlite
Tipriest_3 小时前
vscode snippet 工程模板文件分享
ide·vscode·编辑器
小五Z3 小时前
MySQL--InnoDB存储引擎--架构
数据库·mysql
远方160915 小时前
40-Oracle 23 ai Bigfile~Smallfile-Basicfile~Securefile矩阵对比
数据库·人工智能·sql·oracle·矩阵·database