{"id":1826,"date":"2023-06-27T12:19:23","date_gmt":"2023-06-27T04:19:23","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1826\/"},"modified":"2023-06-27T12:19:23","modified_gmt":"2023-06-27T04:19:23","slug":"gui%e6%80%8e%e4%b9%88%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1826\/","title":{"rendered":"gui\u600e\u4e48\u751f\u6210exe\u6587\u4ef6\uff1f"},"content":{"rendered":"

\u8981\u751f\u6210\u4e00\u4e2a\u5305\u542b\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\uff0c\u53ef\u4ee5\u91c7\u7528\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\u548c\u65b9\u6cd5\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u5206\u522b\u57fa\u4e8ePython\u548cC#\u6765\u4ecb\u7ecd\u751f\u6210EXE\u6587\u4ef6\u7684\u8fc7\u7a0b\u3002<\/p>\n

**Python**<\/p>\n

\u82e5\u8981\u7528Python\u751f\u6210\u5e26\u6709GUI\u7684EXE\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u4e00\u4e2aGUI\u5e93\u3002Tkinter\u662fPython\u9ed8\u8ba4\u81ea\u5e26\u7684\u5e93\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u4ee5Tkinter\u4e3a\u4f8b\u3002<\/p>\n

1. \u5b89\u88c5\u4f9d\u8d56\u5e93\u548c\u5de5\u5177<\/p>\n

\u8981\u6253\u5305Python\u811a\u672c\u4e3aEXE\u6587\u4ef6\uff0c\u6211\u4eec\u9700\u8981PyInstaller\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n

“`bash<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

2. \u7f16\u5199\u793a\u4f8bGUI\u7a0b\u5e8f<\/p>\n

\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`gui_example.py`\u7684\u6587\u4ef6\uff0c\u5e76\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Tkinter GUI\u7a0b\u5e8f\uff1a<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

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

label.config(text=”Hello, ” + entry.get())<\/p>\n

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

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

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

entry.pack()<\/p>\n

button = tk.Button(app, text=”Click me!”, command=on_click)<\/p>\n

button.pack()<\/p>\n

label = tk.Label(app, text=”Welcome!”)<\/p>\n

label.pack()<\/p>\n

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

“`<\/p>\n

\u6b64\u7a0b\u5e8f\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u8f93\u5165\u6846\u3001\u6309\u94ae\u548c\u6807\u7b7e\u7684\u7b80\u5355\u7a97\u53e3\u3002\u5355\u51fb\u6309\u94ae\u65f6\uff0c\u6807\u7b7e\u4f1a\u663e\u793a\u201cHello\u201d\u53ca\u8f93\u5165\u6846\u7684\u5185\u5bb9\u3002<\/p>\n

3. \u751f\u6210EXE\u6587\u4ef6<\/p>\n

\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u5bfc\u822a\u81f3\u5305\u542b`gui_example.py`\u7684\u6587\u4ef6\u5939\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`bash<\/p>\n

pyinstaller –onefile –noconsole gjava\u751f\u621032\u4f4dexe<\/a>ui_example.py<\/p>\n

“`<\/p>\n

`–onefile`\u8868\u793a\u5c06\u7a0b\u5e8f\u6253\u5305\u6210\u5355\u4e2aEXE\u6587\u4ef6\u3002`–noconsole`\u8868\u793a\u5728\u542f\u52a8\u5e94\u7528\u65f6\u4e0d\u4f1a\u663e\u793a\u547d\u4ee4\u884c\u7a97\u53e3\u3002<\/p>\n

\u5b8c\u6210\u4e0a\u8ff0\u64cd\u4f5c\u540e\uff0c\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a`di<\/p>\n

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

st`\u7684\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u751f\u6210\u7684Ematlab\u751f\u6210\u7b80\u5355exe\u4f8b\u5b50<\/a>XE\u6587\u4ef6\u3002\u6253\u5f00\u6b64EXE\u6587\u4ef6\u5373\u53ef\u770b\u5230\u76f8\u5e94\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002<\/p>\n

**C#**<\/p>\n

\u5bf9\u4e8eC#\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Visual Studio\u4f5c\u4e3a\u5f00\u53d1\u73af\u5883\u3002\u4f60\u53ef\u4ee5\u4ece[Visual Studio\u5b98\u7f51](https:\/\/visualstudio.microsoft.com\/)\u4e0b\u8f7d\u514d\u8d39\u7684Visual Studio Community Edition\uff1a<\/p>\n

1. \u6253\u5f00 Visual Studio\uff0c\u9009\u62e9\u201c\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u201d\uff0c\u7136\u540e\u641c\u7d22\u5e76\u9009\u62e9\u201cWindows Forms\u5e94\u7528\u7a0b\u5e8f\u201d\uff08Windows Forms App\uff09\u9879\u76ee\u7c7b\u578b\u3002\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/p>\n

2. \u586b\u5199\u9879\u76ee\u540d\u79f0\u3001\u4f4d\u7f6e\u7b49\u4fe1\u606f\uff0c\u7136\u540e\u70b9\u51fb\u201c\u521b\u5efa\u201d\u3002<\/p>\n

3. Visual Studio\u5c06\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Windows\u7a97\u4f53\u5e94\u7528\u7a0b\u5e8f\u3002\u4f60\u53ef\u4ee5\u5728\u8bbe\u8ba1\u5668\u4e2d\u6dfb\u52a0\u63a7\u4ef6\u548c\u7ec4\u4ef6\uff08\u5982\u6587\u672c\u6846\u3001\u6309\u94ae\u7b49\uff09\uff0c\u5e76\u4e3a\u5176\u7f16\u5199\u76f8\u5e94\u7684\u4ee3\u7801\u3002<\/p>\n

4. \u5b8c\u6210\u7a0b\u5e8f\u540e\uff0c\u9009\u62e9\u201c\u751f\u6210\u201d>\u201c\u751f\u6210 \u89e3\u51b3\u65b9\u6848\u201d\u4ee5\u7f16\u8bd1\u9879\u76ee\u3002 \u7f16\u8bd1\u540e\u7684EXE\u6587\u4ef6\u5c06\u4f4d\u4e8e\u9879\u76ee\u6587\u4ef6\u5939\u4e0b\u7684 `\\bin\\Debug`\u6216`\\bin\\Release`\u76ee\u5f55\u4e0b\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u9009\u62e9\u7684\u7f16\u8bd1\u914d\u7f6e\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662f\u7528Python\u548cC#\u5bf9\u751f\u6210\u5305\u542bGUI\u7684EXE\u6587\u4ef6\u7684\u65b9\u6cd5\u3002\u6839\u636e\u4f60\u719f\u6089\u7684\u7f16\u7a0b\u8bed\u8a00\u548c\u5e73\u53f0\uff0c\u4f60\u4e5f\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6\u5408\u9002\u7684\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8981\u751f\u6210\u4e00\u4e2a\u5305\u542b\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\uff0c\u53ef\u4ee5\u91c7\u7528\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\u548c\u65b9\u6cd5\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u5206\u522b\u57fa\u4e8ePython\u548cC#\u6765\u4ecb\u7ecd\u751f\u6210EXE\u6587\u4ef6\u7684\u8fc7\u7a0b\u3002**Python**\u82e5\u8981\u7528Pyth<\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3886,3885,917,171,398],"class_list":["post-1826","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-javaexe","tag-exe","tag-917","tag-171","tag-398"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1826"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1826\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}