exe\u505a\u6210\u7f51\u9875\u7248<\/a>entry.get())<\/p>\napp = tk.Tk()<\/p>\n
app.title(“\u793a\u4f8bGUI”)<\/p>\n
frame = tk.Frame(app)<\/p>\n
frame.pack(padx=20, pady=20)<\/p>\n
label = tk.Label(frame, text=”\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1a”)<\/p>\n
label.pack(side=tk.LEFT)<\/p>\n
entry = tk.Entry(frame)<\/p>\n
entry.pack(side=tk.LEFT)<\/p>\n
button = tk.Button(frame, text=”\u70b9\u51fb\u6211!”, command=on_click)<\/p>\n
button.pack(side=tk.LEFT, padx=(10, 0))<\/p>\n
app.mainloop()<\/p>\n
“`<\/p>\n
\u5c06\u4ee5\u4e0a\u4ee3\u7801\u4fdd\u5b58\u4e3a`gui_app.py`\u3002<\/p>\n
\u6b65\u9aa42\uff1a\u5b89\u88c5PyInstaller\u5e93<\/p>\n
\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5PyInstaller\u5e93\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n
“`<\/p>\n
pip install pyinstaller<\/p>\n
“`<\/p>\n
\u6b65\u9aa43\uff1a\u5c06Python GUI\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6<\/p>\n
\u6253\u5f00\u547d\u4ee4\u884c\u63d0\u793a\u7b26\uff08CMD\uff09\uff0c\u8fdb\u5165\u4fdd\u5b58Python GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u5939\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n
“`<\/p>\n
pyinstaller –onefile –noconsole gui_app.py<\/p>\n
“`<\/p>\n
\u8be5\u547d\u4ee4\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n
– `–onefile`: \u751f\u6210\u5355\u4e2aexe\u6587\u4ef6\u3002<\/p>\n
– `–noconsole`: \u5728Windows\u4e0a\u8fd0\u884c\u7a0b\u5e8f\u65f6\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n
– `gui_app.py`: \u8981\u8f6c\u6362\u4e3aEXE\u7684Python\u811a\u672c\u3002<\/p>\n
PyInstaller\u5c06\u5f00\u59cb\u6784\u5efaEXE\u6587\u4ef6\u7684\u8fc7\u7a0b\u3002\u5f85\u5176\u5b8c\u6210\u540e\uff0c\u60a8\u5c06\u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u540d\u4e3a’dist’\u7684\u65b0\u6587\u4ef6\u5939\uff0c<\/p>\n
<\/figure>\n<\/p>\n\u5728\u6b64\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u540d\u4e3a’gui_app.exe’\u7684EXE\u6587\u4ef6\u3002<\/p>\n
\u73b0\u5728\uff0c\u53cc\u51fb\u8be5EXE\u6587\u4ef6\uff0c\u5373\u53ef\u8fd0\u884c\u60a8\u7684Python GUI\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u9700Python\u73af\u5883\u3002<\/p>\n
\u539f\u7406\uff1a<\/p>\n
PyInstaller\u901a\u8fc7\u5206\u6790\u811a\u672c\u4e2d\u7684Python\u5bfc\u5165\u8bed\u53e5\uff08\u6bd4\u5982\uff0c`import tkinter`\uff09\u5e76\u81ea\u52a8\u6536\u96c6\u6240\u9700\u7684\u4f9d\u8d56\u5e93\uff0c\u5c06\u811a\u672c\u6253\u5305\u6210\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u3002\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5c06\u5305\u62ec\u5904\u7406\u7a0b\u5e8f\uff08PyInstaller\u81ea\u8eab\u7684\u52a0\u8f7d\u5668\uff09\u3001Python\u89e3\u91ca\u5668\u3001\u811a\u672c\u4ee5\u53ca\u6240\u9700\u5e93\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u786e\u4fdd\u60a8\u65e0\u9700\u62c5\u5fc3\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u7a0b\u5e8f\u65f6\u6240\u9700\u7684\u4efb\u4f55\u4f9d\u8d56\u9879\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u5411\u60a8\u4ecb\u7ecd\u5982\u4f55\u5c06Python GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u7684EXE\u6587\u4ef6\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Python\u7684\u201cPyInstaller\u201d\u5e93\uff0c\u5b83\u662f\u4e13\u95e8\u7528\u4e8e\u751f\u6210Python\u811a\u672c\u7684\u72ec\u7acb<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3621,3620,14,171,283],"class_list":["post-1692","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-javaexe","tag-exe","tag-14","tag-171","tag-283"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1692","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\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1692"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1692\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}