pyqt5界面开发-制作程序集合桌面-基本的框架

pyqt5界面开发-制作程序集合桌面-基本的框架

最近无事,看到了电脑桌面,又想到了最近入门的pyqt5,再看看以往的程序,想到了可不可以做一个集合了多个程序的的UI桌面

先导入pyqt5库

from PyQt5 import QtCore, QtWidgets ,QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QProgressBar, QLabel, QApplication, QMainWindow,QToolTip
from PyQt5.QtCore import QBasicTimer, QThread, pyqtSignal
from PyQt5.QtWidgets import *

然后生成一个类并继承

class UI(QMainWindow,QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

初始化UI

    def init(self):
        QToolTip.setFont(QFont('SansSerif', 10))

        self.resize(1000, 625) #大小
        self.move(300, 300) #窗口初始位置

        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) #设置禁用放大缩小和退出按钮
        self.setFixedSize(self.width(), self.height()) #禁止拉伸

        self.setWindowTitle('TArk-Tools') #取名
        self.setWindowIcon(QIcon('./resource/img/eye.webp')) #设置窗口的图标
        self.setIcon("./resource/img/bg1.jpg") #这里是调用了一个函数,用于换UI背景,稍后创建

        self.win_offQL = QLabel(self) #颜色文本框
        self.win_offQL.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_offQL.setStyleSheet("border-radius:10px;\n""background-color: rgb(170, 0, 0);")
        self.win_offQL.setText("")
        self.win_off = QPushButton(self) #退出按钮
        self.win_off.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_off.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
        self.win_off.setStyleSheet("QPushButton{background:#ff5500;border-radius:10px;}QPushButton:hover{background:red;}")
        self.win_off.setText("")
        self.win_off.clicked.connect(sys.exit)

补上代码里的换背景函数,setIcon这名字…emmmm

	def setIcon(self):
		self.palette = QPalette()
    	self.palette.setBrush(QPalette.Background, QBrush(QPixmap(path)))
    	self.setPalette(self.palette)

换背景在后面很多跳转的地方都要用,所以设置了一个函数

我还想在开始时设一个进度条,这里用到了QTimer代替time

	def main():
		self.interface()
		
    def interface(self):
        self.pbar = QProgressBar(self) #用QProgressBar()设置进度条
        self.pbar.setGeometry(300,400,450,25) #进度条基本信息:(x轴,y轴,长,宽)

        self.button = QPushButton('Start', self)
        self.button.move(450, 450)

        self.button.clicked.connect(self.onStart) #挂到onStart函数
        self.timer = QBasicTimer() #初始化QTimer
        self.step = 0



    def timerEvent(self, event):
        if self.step >= 100:
            self.timer.stop() #停止QTimer
            self.mainApp() #跳转到程序桌面UI,在后期创建
            return 0


        self.step = self.step + 1
        self.pbar.setValue(self.step)


    def onStart(self):
        if self.timer.isActive():
            self.timer.stop()
            self.button.setText('Start')
        else:
            self.timer.start(10, self)
            self.button.setText('Stop')

贴上mainApp的UI代码

	self.win_off.show()
    self.win_offQL.show()

    self.setFixedSize(1000, 625) #重新定义窗口拉伸的长度,宽度

    y1 = 100

    self.hide1() #隐藏函数
    self.setIcon("./resource/img/bg2.jpg")

隐藏函数1

    def hide1(self):
        self.button.hide()
        self.pbar.hide()

最后主函数入口

if __name__ == '__main__':
	def run():
    	app = QApplication(sys.argv)
    	GUI = UI()
    	GUI.show()
    	sys.exit(app.exec_())
    	
	run()

好了,今天的基本框架就这样了,明天将贴出运行图
喜欢此文章请点一个点赞收藏加关注,爱你么么哒(づ ̄3 ̄)づ╭❤~

今天代码又修改了一下

贴上全部代码

from PyQt5 import QtCore, QtWidgets ,QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QProgressBar, QLabel, QApplication, QMainWindow,QToolTip
from PyQt5.QtCore import QBasicTimer, QThread, pyqtSignal
import sys
from PyQt5.QtWidgets import *

class UI(QMainWindow,QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.init()
        self.main()

    def init(self):
        QToolTip.setFont(QFont('SansSerif', 10))

        self.resize(1000, 625)  # 大小
        self.move(300, 300)  # 窗口初始位置

        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)  # 设置禁用放大缩小和退出按钮
        self.setFixedSize(self.width(), self.height())  # 禁止拉伸

        self.setWindowTitle('TArk-Tools')  # 取名
        self.setWindowIcon(QIcon('./resource/img/eye.webp'))  # 设置窗口的图标
        self.setIcon("./resource/img/bg1.jpg")  # 这里是调用了一个函数,用于换UI背景,稍后创建

        self.win_offQL = QLabel(self)  # 颜色文本框
        self.win_offQL.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_offQL.setStyleSheet("border-radius:10px;\n""background-color: rgb(170, 0, 0);")
        self.win_offQL.setText("")
        self.win_off = QPushButton(self)  # 退出按钮
        self.win_off.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_off.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
        self.win_off.setStyleSheet(
            "QPushButton{background:#ff5500;border-radius:10px;}QPushButton:hover{background:red;}")
        self.win_off.setText("")
        self.win_off.clicked.connect(sys.exit)

    def main(self):
        self.interface()

    def interface(self):
        self.pbar = QProgressBar(self)  # 用QProgressBar()设置进度条
        self.pbar.setGeometry(300, 400, 450, 25)  # 进度条基本信息:(x轴,y轴,长,宽)

        self.button = QPushButton('Start', self)
        self.button.move(450, 450)

        self.button.clicked.connect(self.onStart)  # 挂到onStart函数
        self.timer = QBasicTimer()  # 初始化QTimer
        self.step = 0

    def timerEvent(self, event):
        if self.step >= 100:
            self.timer.stop()  # 停止QTimer
            self.mainApp()  # 跳转到程序桌面UI,在后期创建
            return

        self.step = self.step + 1
        self.pbar.setValue(self.step)

    def onStart(self):
        if self.timer.isActive():
            self.timer.stop()
            self.button.setText('Start')
        else:
            self.timer.start(10, self)
            self.button.setText('Stop')

    def setIcon(self,path):
        self.palette = QPalette()
        self.palette.setBrush(QPalette.Background, QBrush(QPixmap(path)))
        self.setPalette(self.palette)


    def mainApp(self):
        self.win_off.show()
        self.win_offQL.show()

        self.setFixedSize(1000, 625)  # 重新定义窗口拉伸的长度,宽度

        y1 = 100

        self.hide1()  # 隐藏函数
        self.setIcon("./resource/img/bg2.jpg")

    def hide1(self):
        self.button.hide()
        self.pbar.hide()


if __name__ == '__main__':
    def run():
        app = QApplication(sys.argv)
        GUI = UI()
        GUI.show()
        sys.exit(app.exec_())

    run()

程序运行图片
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值