西安大型网站开发,大数据营销试卷,图片抗锯齿网站,简约网站后台一. 演示效果 二. 准备工作
1. 使用pip 下载所需包 pyqt5 2. 下载可视化UI工具 QT Designer 链接#xff1a;https://pan.baidu.com/s/1ic4S3ocEF90Y4L1GqYHPPA?pwdywct 提取码#xff1a;ywct 3. 可视化UI工具汉化 把上面的链接打开, 里面有安装和汉化包, 前面的路径还要看…一. 演示效果 二. 准备工作
1. 使用pip 下载所需包 pyqt5 2. 下载可视化UI工具 QT Designer 链接https://pan.baidu.com/s/1ic4S3ocEF90Y4L1GqYHPPA?pwdywct 提取码ywct 3. 可视化UI工具汉化 把上面的链接打开, 里面有安装和汉化包, 前面的路径还要看你安装在哪里, 然后把汉化包直接放到这个文件夹中就可以了 4. pycharm配置QT Designer Arguments: -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py QT Designer作用: 快速打开QT Designer布局工具 PyUIC作用: .ui布局文件转成.py布局文件, 也就是test.ui - test.py 三. 代码
1. 文件结构 2. 代码 test.ui ?xml version1.0 encodingUTF-8?
ui version4.0classMainWindow/classwidget classQMainWindow nameMainWindowproperty namegeometryrectx0/xy0/ywidth800/widthheight600/height/rect/propertyproperty namewindowTitlestringMainWindow/string/propertyproperty nametoolButtonStyleenumQt::ToolButtonIconOnly/enum/propertywidget classQWidget namecentralwidgetwidget classQLabel namelabelproperty namegeometryrectx250/xy90/ywidth91/widthheight41/height/rect/propertyproperty namefontfontpointsize16/pointsizeweight50/weightboldfalse/bold/font/propertyproperty nametextstring欢迎使用/string/property/widgetwidget classQLabel namelabel_2property namegeometryrectx370/xy90/ywidth181/widthheight41/height/rect/propertyproperty namefontfontpointsize16/pointsizeweight75/weightboldtrue/bold/font/propertyproperty nametextstring计时器/string/property/widgetwidget classQLabel namelabel_3property nameenabledbooltrue/bool/propertyproperty namegeometryrectx220/xy100/ywidth21/widthheight21/height/rect/propertyproperty nametextstring//propertyproperty namepixmappixmap../resources/icon/icon.ico/pixmap/propertyproperty namescaledContentsbooltrue/bool/property/widgetwidget classQSlider namehorizontalSliderproperty namegeometryrectx110/xy190/ywidth571/widthheight16/height/rect/propertyproperty namemouseTrackingboolfalse/bool/propertyproperty nameorientationenumQt::Horizontal/enum/property/widgetwidget classQPushButton namepushButtonproperty namegeometryrectx230/xy260/ywidth75/widthheight23/height/rect/propertyproperty nametextstring开始计时/string/property/widgetwidget classQPushButton namepushButton_2property namegeometryrectx430/xy260/ywidth75/widthheight23/height/rect/propertyproperty nametextstring重置计时/string/property/widgetwidget classQLabel namelabel_4property namegeometryrectx700/xy190/ywidth31/widthheight16/height/rect/propertyproperty nametextstring0/string/property/widget/widgetwidget classQStatusBar namestatusbar//widgetresourcesinclude location../resources/icon/qrcResources.qrc//resourcesconnectionsconnectionsenderhorizontalSlider/sendersignalsliderMoved(int)/signalreceiverlabel_4/receiverslotsetNum(int)/slothintshint typesourcelabelx395/xy197/y/hinthint typedestinationlabelx715/xy197/y/hint/hints/connectionconnectionsenderlabel_4/sendersignalwindowIconTextChanged(QString)/signalreceiverhorizontalSlider/receiverslotsetFocus()/slothintshint typesourcelabelx715/xy197/y/hinthint typedestinationlabelx395/xy197/y/hint/hints/connectionconnectionsenderpushButton/sendersignalclicked()/signalreceiverlabel_4/receiverslotupdate()/slothintshint typesourcelabelx267/xy271/y/hinthint typedestinationlabelx715/xy197/y/hint/hints/connection/connections
/ui test.py # -*- coding: utf-8 -*-# Form implementation generated from reading ui file test.ui
#
# Created by: PyQt5 UI code generator 5.15.10
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplicationclass Ui_MainWindow(object):def setupUi(self, MainWindow):MainWindow.setObjectName(MainWindow)MainWindow.resize(800, 600)MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)self.centralwidget QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName(centralwidget)self.label QtWidgets.QLabel(self.centralwidget)self.label.setGeometry(QtCore.QRect(250, 90, 91, 41))font QtGui.QFont()font.setPointSize(16)font.setBold(False)font.setWeight(50)self.label.setFont(font)self.label.setObjectName(label)self.label_2 QtWidgets.QLabel(self.centralwidget)self.label_2.setGeometry(QtCore.QRect(370, 90, 181, 41))font QtGui.QFont()font.setPointSize(16)font.setBold(True)font.setWeight(75)self.label_2.setFont(font)self.label_2.setObjectName(label_2)self.label_3 QtWidgets.QLabel(self.centralwidget)self.label_3.setEnabled(True)self.label_3.setGeometry(QtCore.QRect(220, 100, 21, 21))self.label_3.setText()self.label_3.setPixmap(QtGui.QPixmap(../resources/icon/icon.ico))self.label_3.setScaledContents(True)self.label_3.setObjectName(label_3)self.horizontalSlider QtWidgets.QSlider(self.centralwidget)self.horizontalSlider.setGeometry(QtCore.QRect(110, 190, 571, 16))self.horizontalSlider.setMouseTracking(False)self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)self.horizontalSlider.setObjectName(horizontalSlider)self.pushButton QtWidgets.QPushButton(self.centralwidget)self.pushButton.setGeometry(QtCore.QRect(230, 260, 75, 23))self.pushButton.setObjectName(pushButton)self.pushButton_2 QtWidgets.QPushButton(self.centralwidget)self.pushButton_2.setGeometry(QtCore.QRect(430, 260, 75, 23))self.pushButton_2.setObjectName(pushButton_2)self.label_4 QtWidgets.QLabel(self.centralwidget)self.label_4.setGeometry(QtCore.QRect(700, 190, 31, 16))self.label_4.setObjectName(label_4)MainWindow.setCentralWidget(self.centralwidget)self.statusbar QtWidgets.QStatusBar(MainWindow)self.statusbar.setObjectName(statusbar)MainWindow.setStatusBar(self.statusbar)self.retranslateUi(MainWindow)self.horizontalSlider.sliderMoved[int].connect(self.label_4.setNum) # type: ignoreself.label_4.windowIconTextChanged[QString].connect(self.horizontalSlider.setFocus) # type: ignoreself.pushButton.clicked.connect(self.zidongflush) # type: ignoreQtCore.QMetaObject.connectSlotsByName(MainWindow)def zidongflush(self):# 按钮设置不可点击self.pushButton.setText(进行中...)self.pushButton.setEnabled(False)# 假设 label_4 已经设置了数字文本尝试转换成整数try:numb int(self.label_4.text())except ValueError:numb 10 # 如果不能转换则默认为0for _ in range(numb, -1, -1): # 从 numb 开始递减至 0self.label_4.setText(str(_)) # 设置新的文本self.label_4.update() # 触发重绘self.horizontalSlider.setValue(_)# 等待一段时间模拟计时QtCore.QThread.msleep(1000)QApplication.processEvents() # 让事件循环有机会处理其他事件防止界面卡死self.pushButton.setText(开始计时)self.pushButton.setEnabled(True)def retranslateUi(self, MainWindow):_translate QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate(MainWindow, MainWindow))self.label.setText(_translate(MainWindow, 欢迎使用))self.label_2.setText(_translate(MainWindow, 计时器工具))self.pushButton.setText(_translate(MainWindow, 开始计时))self.pushButton_2.setText(_translate(MainWindow, 重置计时))self.label_4.setText(_translate(MainWindow, 0)) main.py import sysfrom PyQt5.QtWidgets import QApplication, QMainWindowfrom UI.test import Ui_MainWindowif __name__ __main__:# 创建QApplication实例传入系统命令行参数app QApplication(sys.argv)# 创建主窗口一个应用程序通常只有一个主窗口MainWindow QMainWindow()# 加载主窗口的用户界面Ui_MainWindow是自动生成的类用于控制界面布局和元素ui Ui_MainWindow()# 使用ui类中的方法设置主窗口的界面完成界面初始化ui.setupUi(MainWindow)# 设置主窗口的标题MainWindow.setWindowTitle(HG)# 显示主窗口使得用户可以与之交互MainWindow.show()# 运行应用程序直到应用程序结束。这里退出应用程序的条件通常是用户关闭了主窗口sys.exit(app.exec_())
四. 打包- pyinstaller 说明: 桌面软件开发完毕之后, 需要打包成.exe文件, 这样才能分发给其他人使用 下载好之后, 把pyinstaller配置到电脑的PATH中, 这样就可以使用cmd执行了 打包后的样子 完毕!!! 希望可以让刚开始学的小伙伴增加点思路~