{"id":5546,"date":"2023-09-11T12:18:47","date_gmt":"2023-09-11T04:18:47","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=5546"},"modified":"2023-09-11T12:18:47","modified_gmt":"2023-09-11T04:18:47","slug":"gui%e8%b0%83%e7%94%a8%e5%a4%96%e9%83%a8%e7%a8%8b%e5%ba%8f%e7%94%9f%e6%88%90exe%e8%a6%81%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/09\/11\/gui%e8%b0%83%e7%94%a8%e5%a4%96%e9%83%a8%e7%a8%8b%e5%ba%8f%e7%94%9f%e6%88%90exe%e8%a6%81%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f\/","title":{"rendered":"gui\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u751f\u6210exe\u8981\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u4f7f\u7528GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u4ee5\u751f\u6210\u4e00\u4e2aEXE\u6587\u4ef6\u3002\u672c\u6559\u7a0b\u5c06\u6309\u4ee5\u4e0b\u987a\u5e8f\u8fdb\u884c\uff1a\u539f\u7406\u4ecb\u7ecd\u3001\u51c6\u5907\u5de5\u4f5c\u3001\u5b9e\u9645\u64cd\u4f5c\u548c\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n

**\u539f\u7406\u4ecb\u7ecd**<\/p>\n

\u751f\u6210EXE\u6587\u4ef6\u7684\u65b9\u5f0f\u591a\u79cd\u591a\u6837\uff0c\u4f8b\u5982\u4f7f\u7528\u7f16\u8bd1\u5668\u7f16\u8bd1\u6e90\u4ee3\u7801\uff08\u5982C\u3001C++\u3001C#\u548cVB\u7b49\u7f16\u7a0b\u8bed\u8a00\uff09\u6216\u4f7f\u7528\u811a\u672c\u8f6c\u6362\u5de5\u5177\uff08\u5982PyInstaller\u5728Python\u4e2d\uff09\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528GUI\u6765\u8c03\u7528\u7f16\u8bd1\u5668\u6216\u5176\u4ed6\u5de5\u5177\uff0c\u4ee5\u751f\u6210\u6211\u4eec\u9700\u8981\u7684EXE\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

**\u51c6\u5907\u5de5\u4f5c**<\/p>\n

\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\uff0c\u8bf7\u786e\u4fdd\u5df2\u6b63\u786e\u5b89\u88c5\u4ee5\u4e0b\u7a0b\u5e8f\u6216\u5e93\uff1a<\/p>\n

1. \u9488\u5bf9\u6240\u9700\u7f16\u7a0b\u8bed\u8a00\u6216\u6280\u672f\u5b89\u88c5\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u6216\u5de5\u5177\uff0c\u4f8b\u5982\uff1a<\/p>\n

– \u5bf9\u4e8eC \/ C++: \u5b89\u88c5GCC\u6216Visual Studio<\/p>\n

– \u5bf9\u4e8ePython: \u5b89\u88c5Python\u53caPyInstaller\u5e93\u3002<\/p>\n

2. \u5f00\u53d1GUI\u7684\u5de5\u5177\uff0c \u5982\uff1aPyQt5\u3001tkinter\u7b49\u3002<\/p>\n

**\u5b9e\u9645\u64cd\u4f5c**<\/p>\n

\u4ee5\u4e0b\u662f\u5b9e\u73b0\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n

1. \u521b\u5efa\u4e00\u4e2aGUI\u7a0b\u5e8f\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u6309\u94ae\u548c\u4e00\u4e2a\u6587\u672c\u6846\u3002<\/p>\n

<\/figure>\n<\/p>\n

\u6309\u94ae\u7528\u4e8e\u89e6\u53d1\u7f16\u8bd1\u8fc7\u7a0b\uff0c\u6587\u672c\u6846\u663e\u793a\u7f16\u8bd1\u8fc7\u7a0b\u7684\u8f93\u51fa\u4fe1\u606f\u3002<\/p>\n

2. \u5f53\u6309\u94ae\u88ab\u5355\u51fb\u65f6\uff0c\u4eceGUI\u7a0b\u5e8f\u4e2d\u8c03\u7528\u7f16\u8bd1\u5668\u6216\u5176\u4ed6\u5de5\u5177\u751f\u6210EXE\u6587\u4ef6\u3002<\/p>\n

3. \u5c06\u7f16\u8bd1\u5de5\u5177\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5e76\u663e\u793a\u5728GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u672c\u6846\u4e2d\uff08\u53ef\u9009\uff09\u3002<\/p>\n

**\u793a\u4f8b\u4ee3\u7801**<\/p>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u548cPyInstaller\u7684\u7b80\u5355\u793a\u4f8b\u3002\u6211\u4eec\u5c06\u4f7f\u7528Python\u7684tkinter\u5e93\u6765\u521b\u5efaGUI\uff1a<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

import subprocess<\/p>\n

def compile_exe():<\/p>\n

pyinstaller_path = “pyinstaller” # \u6216\u8f93\u5165\u4f60\u7684PyInstaller\u5b8c\u6574\u8def\u5f84<\/p>\n

source_file = “your_script.py” # \u8981\u7f16\u8bd1\u7684Python\u811a\u672c\u540d<\/p>\n<\/p>\n

command = f”{pyinstaller_path} –onefile {source_file}”<\/p>\n<\/p>\n

process = subprocess.Popen(<\/p>\n

command,<\/p>\n

shell=True,<\/p>\n

stdout=subprocess.PIPE,<\/p>\n

stderr=subprocess.PIPE,<\/p>\n

text=True<\/p>\n

)<\/p>\n<\/p>\n

output, errors = process.communicate()<\/p>\n<\/p>\n

output_text.delete(1.0, tk.END)<\/p>\n

output_text.insert(tk.END, output)<\/p>\n

if errors:<\/p>\n

output_text.insert(tk.END, “\\n\\nERRORS:\\n”)<\/p>\n

output_text.insert(tk.END, errors)<\/p>\n

app = tk.Tk()<\/p>\n

app.title(“Exe Generator GUI”)<\/p>\n

app.geometry(“600×400”)<\/p>\n

compile_button = tk.Button(app, text=”Compile”, command=compile_exe)<\/p>\n

compile_button.pack(padx=10, pady=10)<\/p>\n

output_text = tk.Text(app, wrap=tk.WORD)<\/p>\n

output_text.pack\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528<\/a>(expand=True, fill=tk.BOTH)<\/p>\n

app.mainloop()<\/p>\n

“`<\/p>\n

\u6ce8\u610f\uff1a\u8bf7\u786e\u4fdd\u5728\u8fd0\u884c\u6b64\u793a\u4f8b\u4ee3\u7801\u4e4b\u524d\u5b89\u88c5\u4e86Python\u3001PyInstaller\u5e93\u4ee5\u53ca\u6e90\u6587\u4ef6\u8def\u5f84\u5df2\u6b63\u786e\u586b\u5199\u3002<\/p>\n

\u603b\u7ed3\uff1a\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u901a\u8fc7GUI\u8c03\u7528\u5916\u90e8\u7a0bjava\u9879\u76ee\u5982\u4f55\u751f\u6210exe\u6587\u4ef6<\/a>\u5e8f\u4ee5\u751f\u6210EXE\u5e94\u7528\u7a0b\u5e8f\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u6240\u9700\u8981\u7684\u7f16\u7a0b\u8bed\u8a00\u548cGUI\u5e93\u8fdb\u884c\u76f8\u5e94\u7684\u8c03\u6574\u3002\u5982\u679c\u4f60\u9075\u5faa\u672c\u6559\u7a0b\u7684\u6b65\u9aa4, \u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4f60\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762, \u4ee5\u6ee1\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7f16\u8bd1\u4efb\u52a1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u4f7f\u7528GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u4ee5\u751f\u6210\u4e00\u4e2aEXE\u6587\u4ef6\u3002\u672c\u6559\u7a0b\u5c06\u6309\u4ee5\u4e0b\u987a\u5e8f\u8fdb\u884c\uff1a\u539f\u7406\u4ecb\u7ecd\u3001\u51c6\u5907\u5de5\u4f5c\u3001\u5b9e\u9645\u64cd\u4f5c\u548c\u793a\u4f8b\u4ee3\u7801\u3002**\u539f\u7406\u4ecb\u7ecd**\u751f\u6210EXE\u6587\u4ef6\u7684\u65b9\u5f0f\u591a\u79cd\u591a\u6837<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[10261,10260,18,2894,64],"topic":[],"class_list":["post-5546","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-exe","tag-javaexe","tag-18","tag-2894","tag-64"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/5546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=5546"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/5546\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=5546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=5546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=5546"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=5546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}