{"id":3577,"date":"2023-08-11T12:19:08","date_gmt":"2023-08-11T04:19:08","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=3577"},"modified":"2023-08-11T12:19:08","modified_gmt":"2023-08-11T04:19:08","slug":"gui%e7%bc%96%e7%a8%8b%e4%b8%8eexe%e6%89%93%e5%8c%85%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e5%93%aa%e4%ba%9b%e4%ba%8b%e9%a1%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/08\/11\/gui%e7%bc%96%e7%a8%8b%e4%b8%8eexe%e6%89%93%e5%8c%85%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e5%93%aa%e4%ba%9b%e4%ba%8b%e9%a1%b9%ef%bc%9f\/","title":{"rendered":"gui\u7f16\u7a0b\u4e0eexe\u6253\u5305\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f"},"content":{"rendered":"

GUI\u7f16\u7a0b\u4e0eEXE\u6253\u5305(\u539f\u7406\u6216\u8be6\u7ec6\u4ecb\u7ecd)<\/p>\n

\u4e00\u3001GUI\u7f16\u7a0b<\/p>\n

\u56fe\u5f62\u7528\u6237\u754c\u9762(GUI, Graphical User Interface)\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u89c6\u89c9\u5143\u7d20(\u5982\u7a97\u53e3\u3001\u6309\u94ae\u548c\u56fe\u6807\u7b49)\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u7684\u65b9\u5f0f\u3002\u4e0e\u547d\u4ee4\u884c(CLI, Command Line Iunity2018\u6253\u5305exe\u6587\u4ef6<\/a>nterface)\u76f8\u6bd4\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u76f4\u89c2\u3001\u6613\u4e8e\u64cd\u4f5c\u7684\u7528\u6237\u4f53\u9a8c\u3002\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u90fd\u6709\u73b0\u6210\u7684\u5e93\u548c\u6846\u67b6\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u8bbe\u8ba1\u548c\u5b9e\u73b0GUI\u7a0b\u5e8f\u3002<\/p>\n

1. GUI\u5f00\u53d1\u5e93\u4e0e\u6846\u67b6\u793a\u4f8b<\/p>\n

– Python: Tkinter, PyQt, PyGTK<\/p>\n

– C++: Qt, wxWidgets, GTKMM<\/p>\n

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

– Java: Swing, JavaFX<\/p>\n

– C#: Windows Forms, WPF<\/p>\n

2. GUI\u5f00\u53d1\u57fa\u672c\u6b65\u9aa4<\/p>\n

\uff08\u4ee5Python Tkinter\u4e3a\u4f8b\uff09<\/p>\n

– \u5bfc\u5165Tkinter\u5e93: `import tkinter as tk`<\/p>\n

– \u521b\u5efa\u4e3b\u7a97\u53e3\u5bf9\u8c61: `window = tk.Tk()`<\/p>\n

– \u6dfb\u52a0GUI\u7ec4\u4ef6\uff0c\u5982\u6309\u94ae(Button)\u3001\u6807\u7b7e(Label)\u7b49:<\/p>\n

“`<\/p>\n

label = tk.Label(window, text=”Hello World”)<\/p>\n

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

button = tk.Button(window, text=”OK”, command=some_function)<\/p>\n

\u5fae\u8f6f\u8f6f\u4ef6\u5f00\u53d1<\/a>button.pack()<\/p>\n

“`<\/p>\n

– \u4e3b\u4e8b\u4ef6\u5faa\u73af: `window.mainloop()`<\/p>\n

\u5b8c\u6574\u793a\u4f8b:<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

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

print(“Button clicked.”)<\/p>\n

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

window.title(“GUI Programming with Python”)<\/p>\n

label = tk.Label(window, text=”Welcome to GUI Programming!”)<\/p>\n

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

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

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

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

“`<\/p>\n

\u4e8c\u3001EXE\u6253\u5305<\/p>\n

\u7531\u4e8e\u89e3\u91ca\u6027\u8bed\u8a00(\u5982Python)\u4ee3\u7801\u9700\u8981\u901a\u8fc7\u89e3\u91ca\u5668\u8fd0\u884c\uff0c\u56e0\u6b64\u5c06\u8fd9\u4e9b\u4ee3\u7801\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6(EXE)\u53ef\u4ee5\u4f7f\u5176\u5728\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u66f4\u65b9\u4fbf\u5730\u8fd0\u884c\uff0c\u65e0\u9700\u5b89\u88c5\u89e3\u91ca\u5668\u3002\u5e38\u7528\u7684\u6253\u5305\u5de5\u5177\u6709:<\/p>\n

1. Python: PyInstaller, cx_Freeze<\/p>\n

2. Java: Launch4j\uff0cjlink<\/p>\n

3. Ruby: OCRA<\/p>\n

\u4ee5Python\u7684PyInstaller\u4e3a\u4f8b\uff0c\u8fdb\u884cEXE\u6253\u5305\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n

1. \u5b89\u88c5PyInstaller\u5e93\uff1a `pip install pyinstaller`<\/p>\n

2. \u901a\u8fc7\u547d\u4ee4\u884c\uff0c\u5bfc\u822a\u81f3\u6e90\u4ee3\u7801\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff0c\u8fd0\u884c\u547d\u4ee4\uff1a`pyinstaller –onefile your_script.py` (your_script.py\u662f\u4f60\u7684Python\u811a\u672c\u540d)\u3002<\/p>\n

3. \u7b49\u5f85\u7a0b\u5e8f\u5b8c\u6210\u6253\u5305\uff0c\u751f\u6210\u7684EXE\u6587\u4ef6\u5c06\u4f4d\u4e8e”dist”\u6587\u4ef6\u5939\u5185\u3002<\/p>\n

\u6ce8\u610f\uff0c\u6253\u5305\u540e\u7684EXE\u6587\u4ef6\u4ec5\u9002\u7528\u4e8e\u4e0e\u6e90\u8ba1\u7b97\u673a\u76f8\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u3002\u8981\u5728\u5176\u4ed6\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff0c\u9700\u8981\u5728\u76ee\u6807\u7cfb\u7edf\u4e0a\u6267\u884c\u76f8\u540c\u7684\u6253\u5305\u8fc7\u7a0b\u3002\u6b64\u5916\uff0c\u6253\u5305\u65f6\u7684\u6e90\u4ee3\u7801\u8def\u5f84\u4e2d\u4e0d\u5e94\u5305\u542b\u975e\u82f1\u6587\u5b57\u7b26\uff0c\u4ee5\u514d\u51fa\u73b0\u7f16\u7801\u95ee\u9898\u3002<\/p>\n

\u603b\u7ed3\uff1aGUI\u7f16\u7a0b\u8ba9\u6211\u4eec\u521b\u5efa\u66f4\u5177\u5438\u5f15\u529b\u548c\u6613\u7528\u6027\u7684\u7528\u6237\u754c\u9762\u3002\u5c06\u4ee3\u7801\u6253\u5305\u6210\u72ec\u7acb\u7684EXE\u6587\u4ef6\u53ef\u4ee5\u8ba9\u5728\u65e0\u9700\u989d\u5916\u5b89\u88c5\u89e3\u91ca\u5668\u7684\u60c5\u51b5\u4e0b\u66f4\u65b9\u4fbf\u5730\u8fd0\u884c\u7a0b\u5e8f\u3002\u8fd9\u4e24\u8005\u7ed3\u5408\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5f00\u53d1\u51fa\u66f4\u4f18\u79c0\u3001\u6613\u4e8e\u5206\u4eab\u548c\u4f7f\u7528\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

GUI\u7f16\u7a0b\u4e0eEXE\u6253\u5305(\u539f\u7406\u6216\u8be6\u7ec6\u4ecb\u7ecd)\u4e00\u3001GUI\u7f16\u7a0b\u56fe\u5f62\u7528\u6237\u754c\u9762(GUI, Graphical User Interface)\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u89c6\u89c9\u5143\u7d20(\u5982\u7a97\u53e3\u3001\u6309\u94ae\u548c\u56fe\u6807\u7b49)\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u7684\u65b9\u5f0f\u3002\u4e0e\u547d<\/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":[7108,7109,38,7110,12],"topic":[],"class_list":["post-3577","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-pb-exe","tag-7109","tag-38","tag-32exe","tag-12"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/3577","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=3577"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/3577\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=3577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=3577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=3577"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=3577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}