当前位置:   article > 正文

python使用pyqt5制作exe电脑小工具_pyqt5生成exe

pyqt5生成exe

 call_cxtool.py 用来调用界面的开始界面

  1. # -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'connect_me.ui'#
  2. # Created by: PyQt5 UI code generator 5.11.3#
  3. # WARNING! All changes made in this file will be lost!#导入程序运行必须模块
  4. # PyQt5中使用的基本控件都在PyQt5.QtWidgets模块中
  5. import sys
  6. from PyQt5.QtWidgets import QApplication, QMainWindow # #导入designer工具生成的login模块
  7. from cxtool import Ui_ToolMainWindow
  8. class MyMainForm(QMainWindow, Ui_ToolMainWindow):
  9. def __init__(self, parent=None):
  10. super(MyMainForm, self).__init__(parent)
  11. self.setupUi(self)
  12. if __name__ == "__main__":
  13. # 固定的,PyQt5程序都需要QApplication对象。sys.argv是命令行参数列表,确保程序可以双击运行
  14. app = QApplication(sys.argv)
  15. # 初始化
  16. myWin = MyMainForm()
  17. # 将窗口控件显示在屏幕上
  18. myWin.show()
  19. # 程序运行,sys.exit方法确保程序完整退出。
  20. sys.exit(app.exec_())

tool.ui是通过pt designer生成的ui界面,通过PyUIc转化为tool.py (转化方法后续放)

cxtool.py

  1. # -*- coding: utf-8 -*-
  2. # Form implementation generated from reading ui file 'cxtool.ui'
  3. #
  4. # Created by: PyQt5 UI code generator 5.15.4
  5. #
  6. # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  7. # run again. Do not edit this file unless you know what you are doing.
  8. import json
  9. import os
  10. import sys
  11. from configparser import ConfigParser
  12. from shutil import copyfile
  13. import psutil
  14. import win32api
  15. import wmi
  16. from PyQt5 import QtCore, QtGui, QtWidgets
  17. from PyQt5.QtWidgets import QMessageBox
  18. import func_impl
  19. import function_impl
  20. cp = ConfigParser()
  21. cp.read('config.cfg')
  22. current_working_dir = os.getcwd()
  23. cp.set("database", "root_path", current_working_dir) # 使用set直接修改指定字段值
  24. with open("config.cfg", "w+") as f:
  25. cp.write(f)
  26. root_path = cp.get('database', 'root_path')
  27. class Ui_ToolMainWindow(object):
  28. def setupUi(self, ToolMainWindow):
  29. ToolMainWindow.setObjectName("ToolMainWindow")
  30. ToolMainWindow.resize(781, 619)
  31. self.centralwidget = QtWidgets.QWidget(ToolMainWindow)
  32. self.centralwidget.setObjectName("centralwidget")
  33. self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
  34. self.tabWidget.setGeometry(QtCore.QRect(0, 0, 791, 691))
  35. self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
  36. self.tabWidget.setStyleSheet("*{\n"
  37. " font: 75 11pt \"微软雅黑\";\n"
  38. "font-weight: bold;\n"
  39. "color:yellow;\n"
  40. "}\n"
  41. "")
  42. self.tabWidget.setIconSize(QtCore.QSize(88, 28))
  43. self.tabWidget.setObjectName("tabWidget")
  44. self.tab_1 = QtWidgets.QWidget()
  45. self.tab_1.setObjectName("tab_1")
  46. self.checkBox_ie_set = QtWidgets.QCheckBox(self.tab_1)
  47. self.checkBox_ie_set.setGeometry(QtCore.QRect(110, 60, 131, 19))
  48. self.checkBox_ie_set.setCheckable(True)
  49. self.checkBox_ie_set.setObjectName("checkBox_ie_set")
  50. self.checkBox_host_domain_map = QtWidgets.QCheckBox(self.tab_1)
  51. self.checkBox_host_domain_map.setGeometry(QtCore.QRect(450, 60, 181, 19))
  52. self.checkBox_host_domain_map.setObjectName("checkBox_host_domain_map")
  53. self.checkBox_c_clear = QtWidgets.QCheckBox(self.tab_1)
  54. self.checkBox_c_clear.setGeometry(QtCore.QRect(300, 60, 131, 19))
  55. self.checkBox_c_clear.setObjectName("checkBox_c_clear")
  56. self.checkBox_restart_print_service = QtWidgets.QCheckBox(self.tab_1)
  57. self.checkBox_restart_print_service.setGeometry(QtCore.QRect(300, 100, 131, 19))
  58. self.checkBox_restart_print_service.setObjectName("checkBox_restart_print_service")
  59. self.checkBox_clear_all_tasks = QtWidgets.QCheckBox(self.tab_1)
  60. self.checkBox_clear_all_tasks.setGeometry(QtCore.QRect(110, 100, 171, 19))
  61. self.checkBox_clear_all_tasks.setObjectName("checkBox_clear_all_tasks")
  62. self.checkBox_fix_dns = QtWidgets.QCheckBox(self.tab_1)
  63. self.checkBox_fix_dns.setGeometry(QtCore.QRect(110, 140, 151, 19))
  64. self.checkBox_fix_dns.setObjectName("checkBox_fix_dns")
  65. self.checkBox_update_AD_domain_strategy = QtWidgets.QCheckBox(self.tab_1)
  66. self.checkBox_update_AD_domain_strategy.setGeometry(QtCore.QRect(300, 140, 151, 19))
  67. self.checkBox_update_AD_domain_strategy.setObjectName("checkBox_update_AD_domain_strategy")
  68. self.line = QtWidgets.QFrame(self.tab_1)
  69. self.line.setGeometry(QtCore.QRect(310, 20, 341, 31))
  70. self.line.setFrameShape(QtWidgets.QFrame.HLine)
  71. self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
  72. self.line.setObjectName("line")
  73. self.line_2 = QtWidgets.QFrame(self.tab_1)
  74. self.line_2.setGeometry(QtCore.QRect(70, 50, 20, 121))
  75. self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
  76. self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
  77. self.line_2.setObjectName("line_2")
  78. self.line_3 = QtWidgets.QFrame(self.tab_1)
  79. self.line_3.setGeometry(QtCore.QRect(660, 50, 20, 121))
  80. self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
  81. self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
  82. self.line_3.setObjectName("line_3")
  83. self.line_4 = QtWidgets.QFrame(self.tab_1)
  84. self.line_4.setGeometry(QtCore.QRect(90, 160, 561, 31))
  85. self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
  86. self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
  87. self.line_4.setObjectName("line_4")
  88. self.label_proxy_ip_address = QtWidgets.QLabel(self.tab_1)
  89. self.label_proxy_ip_address.setGeometry(QtCore.QRect(90, 210, 111, 21))
  90. self.label_proxy_ip_address.setObjectName("label_proxy_ip_address")
  91. self.lineEdit_proxy_ip_address = QtWidgets.QLineEdit(self.tab_1)
  92. self.lineEdit_proxy_ip_address.setGeometry(QtCore.QRect(210, 210, 151, 31))
  93. self.lineEdit_proxy_ip_address.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  94. "font-weight: bold;\n"
  95. "color:blue;}")
  96. self.lineEdit_proxy_ip_address.setObjectName("lineEdit_proxy_ip_address")
  97. self.label_proxy_port = QtWidgets.QLabel(self.tab_1)
  98. self.label_proxy_port.setGeometry(QtCore.QRect(100, 260, 111, 21))
  99. self.label_proxy_port.setObjectName("label_proxy_port")
  100. self.lineEdit_proxy_port = QtWidgets.QLineEdit(self.tab_1)
  101. self.lineEdit_proxy_port.setGeometry(QtCore.QRect(210, 260, 111, 31))
  102. self.lineEdit_proxy_port.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  103. "font-weight: bold;\n"
  104. "color:blue;}")
  105. self.lineEdit_proxy_port.setObjectName("lineEdit_proxy_port")
  106. self.lineEdit_dns_1 = QtWidgets.QLineEdit(self.tab_1)
  107. self.lineEdit_dns_1.setGeometry(QtCore.QRect(560, 310, 181, 31))
  108. self.lineEdit_dns_1.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  109. "font-weight: bold;\n"
  110. "color:blue;}")
  111. self.lineEdit_dns_1.setObjectName("lineEdit_dns_1")
  112. self.label_dns_4 = QtWidgets.QLabel(self.tab_1)
  113. self.label_dns_4.setGeometry(QtCore.QRect(460, 310, 111, 21))
  114. self.label_dns_4.setObjectName("label_dns_4")
  115. self.lineEdit_default_gateway = QtWidgets.QLineEdit(self.tab_1)
  116. self.lineEdit_default_gateway.setGeometry(QtCore.QRect(560, 270, 181, 31))
  117. self.lineEdit_default_gateway.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  118. "font-weight: bold;\n"
  119. "color:blue;}")
  120. self.lineEdit_default_gateway.setObjectName("lineEdit_default_gateway")
  121. self.label_default_gateway = QtWidgets.QLabel(self.tab_1)
  122. self.label_default_gateway.setGeometry(QtCore.QRect(460, 270, 111, 21))
  123. self.label_default_gateway.setObjectName("label_default_gateway")
  124. self.lineEdit_subnet_mask = QtWidgets.QLineEdit(self.tab_1)
  125. self.lineEdit_subnet_mask.setGeometry(QtCore.QRect(560, 230, 181, 31))
  126. self.lineEdit_subnet_mask.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  127. "font-weight: bold;\n"
  128. "color:blue;}")
  129. self.lineEdit_subnet_mask.setObjectName("lineEdit_subnet_mask")
  130. self.label_subnet_mask_2 = QtWidgets.QLabel(self.tab_1)
  131. self.label_subnet_mask_2.setGeometry(QtCore.QRect(460, 230, 111, 21))
  132. self.label_subnet_mask_2.setObjectName("label_subnet_mask_2")
  133. self.lineEdit_ip_address = QtWidgets.QLineEdit(self.tab_1)
  134. self.lineEdit_ip_address.setGeometry(QtCore.QRect(560, 190, 181, 31))
  135. self.lineEdit_ip_address.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  136. "font-weight: bold;\n"
  137. "color:blue;}")
  138. self.lineEdit_ip_address.setText("")
  139. self.lineEdit_ip_address.setObjectName("lineEdit_ip_address")
  140. self.label_ip_address = QtWidgets.QLabel(self.tab_1)
  141. self.label_ip_address.setGeometry(QtCore.QRect(480, 190, 111, 21))
  142. self.label_ip_address.setStyleSheet("")
  143. self.label_ip_address.setObjectName("label_ip_address")
  144. self.lineEdit_dns_2 = QtWidgets.QLineEdit(self.tab_1)
  145. self.lineEdit_dns_2.setGeometry(QtCore.QRect(560, 350, 181, 31))
  146. self.lineEdit_dns_2.setStyleSheet("*{font: 12pt \"阿里巴巴普惠体 R\";\n"
  147. "font-weight: bold;\n"
  148. "color:blue;}")
  149. self.lineEdit_dns_2.setObjectName("lineEdit_dns_2")
  150. self.label_dns_3 = QtWidgets.QLabel(self.tab_1)
  151. self.label_dns_3.setGeometry(QtCore.QRect(460, 350, 111, 21))
  152. self.label_dns_3.setObjectName("label_dns_3")
  153. self.pushButton_software_download = QtWidgets.QPushButton(self.tab_1)
  154. self.pushButton_software_download.setGeometry(QtCore.QRect(120, 410, 181, 81))
  155. self.pushButton_software_download.setStyleSheet("*{\n"
  156. "font: 12pt \"阿里巴巴普惠体 R\";\n"
  157. "font-weight: bold;\n"
  158. "color:blue;\n"
  159. "}\n"
  160. "")
  161. self.pushButton_software_download.setObjectName("pushButton_software_download")
  162. self.pushButton_onepush = QtWidgets.QPushButton(self.tab_1)
  163. self.pushButton_onepush.setGeometry(QtCore.QRect(460, 410, 181, 81))
  164. self.pushButton_onepush.setStyleSheet("*{\n"
  165. "font: 15pt \"阿里巴巴普惠体 R\";\n"
  166. "font-weight: bold;\n"
  167. "color:blue;\n"
  168. "}\n"
  169. "")
  170. self.pushButton_onepush.setObjectName("pushButton_onepush")
  171. self.label_version_1 = QtWidgets.QLabel(self.tab_1)
  172. self.label_version_1.setGeometry(QtCore.QRect(20, 530, 161, 16))
  173. self.label_version_1.setStyleSheet("*{\n"
  174. " font: 75 10pt \"微软雅黑\";\n"
  175. "font-weight: bold;\n"
  176. "color:white;\n"
  177. "}")
  178. self.label_version_1.setObjectName("label_version_1")
  179. self.line_9 = QtWidgets.QFrame(self.tab_1)
  180. self.line_9.setGeometry(QtCore.QRect(80, 190, 291, 16))
  181. self.line_9.setFrameShape(QtWidgets.QFrame.HLine)
  182. self.line_9.setFrameShadow(QtWidgets.QFrame.Sunken)
  183. self.line_9.setObjectName("line_9")
  184. self.line_10 = QtWidgets.QFrame(self.tab_1)
  185. self.line_10.setGeometry(QtCore.QRect(70, 210, 16, 141))
  186. self.line_10.setFrameShape(QtWidgets.QFrame.VLine)
  187. self.line_10.setFrameShadow(QtWidgets.QFrame.Sunken)
  188. self.line_10.setObjectName("line_10")
  189. self.line_11 = QtWidgets.QFrame(self.tab_1)
  190. self.line_11.setGeometry(QtCore.QRect(80, 360, 291, 16))
  191. self.line_11.setFrameShape(QtWidgets.QFrame.HLine)
  192. self.line_11.setFrameShadow(QtWidgets.QFrame.Sunken)
  193. self.line_11.setObjectName("line_11")
  194. self.line_12 = QtWidgets.QFrame(self.tab_1)
  195. self.line_12.setGeometry(QtCore.QRect(370, 210, 16, 141))
  196. self.line_12.setFrameShape(QtWidgets.QFrame.VLine)
  197. self.line_12.setFrameShadow(QtWidgets.QFrame.Sunken)
  198. self.line_12.setObjectName("line_12")
  199. self.groupBox = QtWidgets.QGroupBox(self.tab_1)
  200. self.groupBox.setGeometry(QtCore.QRect(190, 310, 141, 51))
  201. self.groupBox.setStyleSheet("*{\n"
  202. "font: 75 9pt \"微软雅黑\";\n"
  203. "color:white\n"
  204. "}")
  205. self.groupBox.setTitle("")
  206. self.groupBox.setObjectName("groupBox")
  207. self.radioButton_switch_off = QtWidgets.QRadioButton(self.groupBox)
  208. self.radioButton_switch_off.setGeometry(QtCore.QRect(80, 20, 51, 19))
  209. self.radioButton_switch_off.setStyleSheet("*{\n"
  210. " font: 75 11pt \"微软雅黑\";\n"
  211. "font-weight: bold;\n"
  212. "color:yellow;\n"
  213. "}")
  214. self.radioButton_switch_off.setChecked(True)
  215. self.radioButton_switch_off.setObjectName("radioButton_switch_off")
  216. self.radioButton_switch_on = QtWidgets.QRadioButton(self.groupBox)
  217. self.radioButton_switch_on.setGeometry(QtCore.QRect(20, 20, 61, 19))
  218. self.radioButton_switch_on.setStyleSheet("*{\n"
  219. " font: 75 11pt \"微软雅黑\";\n"
  220. "font-weight: bold;\n"
  221. "color:yellow;\n"
  222. "}")
  223. self.radioButton_switch_on.setChecked(False)
  224. self.radioButton_switch_on.setObjectName("radioButton_switch_on")
  225. self.groupBox_2 = QtWidgets.QGroupBox(self.tab_1)
  226. self.groupBox_2.setGeometry(QtCore.QRect(110, 20, 201, 31))
  227. self.groupBox_2.setStyleSheet("*{\n"
  228. "\n"
  229. "font: 75 9pt \"微软雅黑\";\n"
  230. "color:white;\n"
  231. "}")
  232. self.groupBox_2.setTitle("")
  233. self.groupBox_2.setObjectName("groupBox_2")
  234. self.radioButton_cancel_all = QtWidgets.QRadioButton(self.groupBox_2)
  235. self.radioButton_cancel_all.setGeometry(QtCore.QRect(90, 0, 101, 19))
  236. self.radioButton_cancel_all.setStyleSheet("*{\n"
  237. " font: 75 10pt \"微软雅黑\";\n"
  238. "font-weight: bold;\n"
  239. "color:yellow;\n"
  240. "}\n"
  241. "")
  242. self.radioButton_cancel_all.setObjectName("radioButton_cancel_all")
  243. self.radioButton_all = QtWidgets.QRadioButton(self.groupBox_2)
  244. self.radioButton_all.setGeometry(QtCore.QRect(20, 0, 61, 19))
  245. self.radioButton_all.setStyleSheet("*{\n"
  246. " font: 75 10pt \"微软雅黑\";\n"
  247. "font-weight: bold;\n"
  248. "color:yellow;\n"
  249. "}\n"
  250. "")
  251. self.radioButton_all.setObjectName("radioButton_all")
  252. self.listView = QtWidgets.QListView(self.tab_1)
  253. self.listView.setGeometry(QtCore.QRect(-60, -20, 831, 631))
  254. self.listView.setStyleSheet("background:url(:/picture/light.jpeg)")
  255. self.listView.setObjectName("listView")
  256. self.line_5 = QtWidgets.QFrame(self.tab_1)
  257. self.line_5.setGeometry(QtCore.QRect(0, 510, 771, 16))
  258. self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
  259. self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
  260. self.line_5.setObjectName("line_5")
  261. self.line_7 = QtWidgets.QFrame(self.tab_1)
  262. self.line_7.setGeometry(QtCore.QRect(90, 30, 21, 20))
  263. self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
  264. self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
  265. self.line_7.setObjectName("line_7")
  266. self.label = QtWidgets.QLabel(self.tab_1)
  267. self.label.setGeometry(QtCore.QRect(100, 330, 91, 16))
  268. self.label.setObjectName("label")
  269. self.line_8 = QtWidgets.QFrame(self.tab_1)
  270. self.line_8.setGeometry(QtCore.QRect(0, 550, 771, 16))
  271. self.line_8.setFrameShape(QtWidgets.QFrame.HLine)
  272. self.line_8.setFrameShadow(QtWidgets.QFrame.Sunken)
  273. self.line_8.setObjectName("line_8")
  274. self.line_16 = QtWidgets.QFrame(self.tab_1)
  275. self.line_16.setGeometry(QtCore.QRect(160, 520, 20, 41))
  276. self.line_16.setFrameShape(QtWidgets.QFrame.VLine)
  277. self.line_16.setFrameShadow(QtWidgets.QFrame.Sunken)
  278. self.line_16.setObjectName("line_16")
  279. self.line_17 = QtWidgets.QFrame(self.tab_1)
  280. self.line_17.setGeometry(QtCore.QRect(0, 520, 20, 41))
  281. self.line_17.setFrameShape(QtWidgets.QFrame.VLine)
  282. self.line_17.setFrameShadow(QtWidgets.QFrame.Sunken)
  283. self.line_17.setObjectName("line_17")
  284. self.listView.raise_()
  285. self.checkBox_ie_set.raise_()
  286. self.checkBox_host_domain_map.raise_()
  287. self.checkBox_c_clear.raise_()
  288. self.checkBox_restart_print_service.raise_()
  289. self.checkBox_clear_all_tasks.raise_()
  290. self.checkBox_fix_dns.raise_()
  291. self.checkBox_update_AD_domain_strategy.raise_()
  292. self.line.raise_()
  293. self.line_2.raise_()
  294. self.line_3.raise_()
  295. self.line_4.raise_()
  296. self.label_proxy_ip_address.raise_()
  297. self.lineEdit_proxy_ip_address.raise_()
  298. self.label_proxy_port.raise_()
  299. self.lineEdit_proxy_port.raise_()
  300. self.lineEdit_dns_1.raise_()
  301. self.label_dns_4.raise_()
  302. self.lineEdit_default_gateway.raise_()
  303. s
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/264666
推荐阅读
相关标签
  

闽ICP备14008679号