python pyinstaller GUI源代码
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QTextEdit, QCheckBox, QLabel, QFileDialog from PyQt5.QtGui import QIcon import sys import os import subprocess class WinDow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("pyinstaller_GUI-0.8") self.setMinimumSize(500 , 300) self.setMaximumSize(500 , 300) self.setWindowIcon(QIcon("pussy.ico")) self.wenjian_ui() self.ico_ui() self.anniu_ui() self.qingchu_ui() self.zhuomian_ui() self.tishi_ui() self.banben_ui() self.anzhuang_ui() self.anzhuang_anniu() self.xianshi_anniu() self.tishi2_ui() self.minglingchuang_ui() self.tishi3_ui() self.wenjian_anniu() self.ico_anniu() self.sczdwz_ui() self.sczdwz_xx() self.baocun_anniu() self.sczdwz_tishi() def wenjian_ui(self): wenjian = QTextEdit(self) self.wenjian = wenjian wenjian.resize(480-50-20 , 150-50-50) wenjian.move(10,30) wenjian.setPlaceholderText("可拖拽py文件至此:") wenjian.setTabChangesFocus(True) def ico_ui(self): ico = QTextEdit(self) self.ico = ico ico.resize(480-50-20 , 50) ico.move(10,190-50-50) ico.setPlaceholderText("可拖拽ico文件至此:") ico.setTabChangesFocus(True) def anniu_ui(self): anniu = QPushButton(self) self.anniu = anniu anniu.setText("打包生成EXE") anniu.move(415 , 340-105) anniu.resize(80,60) self.anniu.clicked.connect(self.anniu_cao) def qingchu_ui(self): qingchu = QPushButton(self) self.qingchu = qingchu qingchu.setText("清空") qingchu.move(415 , 340-105-40) self.qingchu.clicked.connect(self.qingchu_cao) def zhuomian_ui(self): zhuomian = QCheckBox(self) self.zhuomian = zhuomian zhuomian.setText("输出到桌面") zhuomian.move(20, 345-110-40) # zhuomian.toggled.connect(lambda isChecked :print(isChecked)) def guanbibaocun(): if self.zhuomian.isChecked() == True: self.sczdwzan.setChecked(False) self.sczdwz.setText("") self.baocunanniu.close() elif self.zhuomian.isChecked() == False and self.baocunanniu.isChecked() ==True: self.baocunanniu.show() zhuomian.clicked.connect(guanbibaocun) def tishi_ui(self): tishi = QLabel(self) self.tishi = tishi tishi.setText("支持XP,Win7,Win10等打包到桌面") tishi.setStyleSheet('background-color: rgb(255, 251, 100)') tishi.move(5, 365-113-40) def banben_ui(self): banben = QLabel(self) self.banben = banben banben.move(10, 10) cmd = 'pyinstaller -v' pivi = subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # print(pivi) self.bbpi = pivi if self.bbpi == 0: banben.setText("您已安装PyInstaller") else: banben.setText("您目前还没安装PyInstaller") banben.setStyleSheet('color:rgb(255, 10, 10)') def anzhuang_ui(self): anzhuang = QLabel(self) self.anzhuang = anzhuang anzhuang.move(300,10) if self.bbpi == 0: anzhuang.setText("") else: anzhuang.setText("我要安装PyInstaller") def anzhuang_anniu(self): azan = QPushButton(self) self.azan = azan azan.move(415,3) if self.bbpi == 0: azan.close() else: azan.setText("我要安装") azan.clicked.connect(self.anzhuang_cao) def anzhuang_cao(self): a = "pip install pyinstaller" os.system(a) def xianshi_anniu(self): xianshi = QCheckBox(self) self.xianshi = xianshi xianshi.setText("使用显式处理") xianshi.move(20, 265-40) def tishi2_ui(self): tishi2 = QLabel(self) self.tishi2 = tishi2 tishi2.setText("默认使用隐式,显式处理为弹出打包的命令行界面") tishi2.setStyleSheet('background-color: rgb(255, 251, 100)') tishi2.move(5, 280-40) def minglingchuang_ui(self): minglingchuang = QCheckBox(self) self.minglingchuang = minglingchuang minglingchuang.setText("使用命令窗") minglingchuang.move(20, 255) def tishi3_ui(self): tishi3 = QLabel(self) self.tishi3 = tishi3 tishi3.setText("注意:命令行程序请勾选此选项,否则运行时会提示以下报错\n failed to execute scipt XXX") tishi3.setStyleSheet('background-color: rgb(255, 251, 100)') tishi3.move(5, 280-10) def wenjian_anniu(self): wenjiananniu = QPushButton(self) self.wenjiananniu = wenjiananniu wenjiananniu.setText("选择py文件") wenjiananniu.move(430-10, 30+10) # wenjiananniu.resize(30,30) wenjiananniu.adjustSize() wenjiananniu.clicked.connect(self.dakaiwenjian_cao) def dakaiwenjian_cao(self): # dakaiwenjian = QFileDialog.getOpenFileUrl(self) dakaiwenjian = QFileDialog.getOpenFileName(self, "请选择一个PY文件", "./", "python文件(*.py)", "python文件(*.py)") # print(dakaiwenjian) self.wenjian.setText("file:///"+str(dakaiwenjian[0])) def ico_anniu(self): icoanniu = QPushButton(self) self.icoanniu = icoanniu icoanniu.setText("选择ico文件") icoanniu.move(430 - 10, 30 + 10+50+10) # wenjiananniu.resize(30,30) icoanniu.adjustSize() icoanniu.clicked.connect(self.dakaiico_cao) def dakaiico_cao(self): # dakaiwenjian = QFileDialog.getOpenFileUrl(self) dakaiico = QFileDialog.getOpenFileName(self, "请选择一个ico文件", "./", "ico文件(*.ico)", "ico文件(*.ico)") # print(dakaiico) self.ico.setText("file:///"+str(dakaiico[0])) def sczdwz_ui(self): sczdwz = QTextEdit(self) self.sczdwz = sczdwz sczdwz.setText("") sczdwz.move(10 , 170) sczdwz.resize(480-50-20 , 150-50-50-25) sczdwz.setReadOnly(True) def sczdwz_xx(self): sczdwzan = QCheckBox(self) self.sczdwzan = sczdwzan sczdwzan.setText("打包文件输出到指定位置") sczdwzan.move(20, 345-110-60-25-10) def guanbizhuomian(): if sczdwzan.isChecked() == True: self.zhuomian.setChecked(False) self.baocunanniu.show() else: self.baocunanniu.close() self.sczdwz.setText("") sczdwzan.clicked.connect(guanbizhuomian) def baocun_anniu(self): baocunanniu = QPushButton(self) self.baocunanniu = baocunanniu baocunanniu.setText("选择保存路径") baocunanniu.move(480-50-10 , 345-110-60-5) # wenjiananniu.resize(30,30) baocunanniu.adjustSize() baocunanniu.clicked.connect(self.baocunlujin_cao) baocunanniu.close() def sczdwz_tishi(self): sczdwzts = QLabel(self) self.sczdwzts = sczdwzts sczdwzts.setText("打钩后才会显示选择按钮") sczdwzts.move(5, 345-110-60-20) sczdwzts.setStyleSheet('background-color: rgb(255, 251, 100)') def baocunlujin_cao(self): baocunlujin = QFileDialog.getExistingDirectory(self) # print(baocunlujin) self.sczdwz.setText(baocunlujin) def anniu_cao(self): if self.minglingchuang.isChecked() == True: if self.xianshi.isChecked() == True: if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() h = " --distpath=%UserProfile%/Desktop/dist" self.k = i + j[8:] + h shuchu = self.k # print(shuchu) os.system(shuchu) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() self.k = i + j[8:] shuchu = self.k # print(shuchu) os.system(shuchu) elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=%UserProfile%/Desktop/dist" self.k = i + h[8:] + " " + j[8:] + m shuchu = self.k os.system(shuchu) # print(shuchu) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() self.k = i + h[8:] + " " + j[8:] shuchu = self.k os.system(shuchu) # print(shuchu) #这是一段 elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() h = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + j[8:] + h + s shuchu = self.k # print(shuchu) os.system(shuchu) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + h[8:] + " " + j[8:] + m + s shuchu = self.k os.system(shuchu) # print(shuchu) else: pass else: if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() h = " --distpath=%UserProfile%/Desktop/dist" self.k = i + j[8:] + h shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() self.k = i + j[8:] shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=%UserProfile%/Desktop/dist" self.k = i + h[8:] + " " + j[8:] + m shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() self.k = i + h[8:] + " " + j[8:] shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #这是第二段 elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F " j = self.wenjian.toPlainText() h = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + j[8:] + h + s shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + h[8:] + " " + j[8:] + m + s shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: pass else: if self.xianshi.isChecked() == True: if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() h = " --distpath=%UserProfile%/Desktop/dist" self.k = i + j[8:] + h shuchu = self.k # print(shuchu) os.system(shuchu) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() self.k = i + j[8:] shuchu = self.k # print(shuchu) os.system(shuchu) elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=%UserProfile%/Desktop/dist" self.k = i + h[8:] + " " + j[8:] + m shuchu = self.k os.system(shuchu) # print(shuchu) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() self.k = i + h[8:] + " " + j[8:] shuchu = self.k os.system(shuchu) # print(shuchu) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() h = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + j[8:] + h + s shuchu = self.k # print(shuchu) os.system(shuchu) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + h[8:] + " " + j[8:] + m + s shuchu = self.k os.system(shuchu) # print(shuchu) else: pass else: if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() h = " --distpath=%UserProfile%/Desktop/dist" self.k = i + j[8:] + h shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() self.k = i + j[8:] shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=%UserProfile%/Desktop/dist" self.k = i + h[8:] + " " + j[8:] + m shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() self.k = i + h[8:] + " " + j[8:] shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "": i = "pyinstaller -F -w " j = self.wenjian.toPlainText() h = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + j[8:] + h + s shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "": i = "pyinstaller -F -w -i " j = self.wenjian.toPlainText() h = self.ico.toPlainText() m = " --distpath=" s = self.sczdwz.toPlainText() self.k = i + h[8:] + " " + j[8:] + m + s shuchu = self.k # print(shuchu) subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: pass def qingchu_cao(self): self.wenjian.clear() self.ico.clear() self.sczdwz.clear() if __name__ == "__main__": app = QApplication(sys.argv) window = WinDow() window.show() sys.exit(app.exec())