{"id":1699,"date":"2023-06-26T12:19:24","date_gmt":"2023-06-26T04:19:24","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=1699"},"modified":"2023-06-26T12:19:24","modified_gmt":"2023-06-26T04:19:24","slug":"gui%e6%80%8e%e4%b9%88%e7%94%9f%e6%88%90exe%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1699\/","title":{"rendered":"gui\u600e\u4e48\u751f\u6210exe\uff1f"},"content":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u5c06GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u5e94\u7528\u7a0b\u5e8f\u751f\u6210\u4e3a\u72ec\u7acb\u7684exe\u6587\u4ef6\uff08\u53ef\u6267\u884c\u6587\u4ef6\uff09\u3002\u8fd9\u5bf9\u4e8e\u521b\u5efa\u53ef\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u72ec\u7acb\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5f53\u7528\u6237\u6ca1\u6709\u5b89\u88c5\u6240\u9700\u7684\u8fd0\u884c\u73af\u5883\uff08\u5982Python\uff09\u65f6\u3002<\/p>\n

\u5728\u6784\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5404\u79cd\u5e93\u5982Tkinter\uff0cPyQt5\uff0cKivy\u7b49\u3002\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Tkinter\uff0c\u4f46\u4ee5\u4e0b\u6b65\u9aa4\u540c\u6837\u9002\u7528\u4e8e\u5176\u4ed6\u5e93\u3002<\/p>\n

\u6b65\u9aa41\uff1a\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python GUI \u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u8ba9\u6211\u4eec\u4ece\u4e66\u5199\u4e00\u4e2a\u7b80\u5355\u7684GUI\u5e94\u7528\u7a0b\u5e8f\u5f00\u59cb\u3002\u8fd9\u4e2a\u793a\u4f8b\u4ec5\u7528\u4e8e\u5c55\u793a\u5982\u4f55\u5c06\u5176\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Tkinter\u793a\u4f8b\uff1a<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

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

label.config(text=”Hello Tkinter!”)<\/p>\n

app = tk.T\u7f51\u5740\u751f\u6210exe<\/a>k()<\/p>\n

app.title(“My Tkinter App”)<\/p>\n

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

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

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

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

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

“`<\/p>\n

\u5c06\u6b64\u4ee3\u7801\u4fdd\u5b58\u4e3a`my_tkinter_app.py`\u3002\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cTkinter\u5e93\u3002<\/p>\n

\u6b65\u9aa42\uff1a\u5b89\u88c5 pyinstaller\u5e93<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u540d\u4e3aPyInstaller\u7684\u7b2c\u4e09\u65b9\u5e93\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PyInstaller\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

\u6b65\u9aa43\uff1a\u4f7f\u7528PyInstaller\u751f\u6210exe\u6587\u4ef6<\/p>\n

\u5b89\u88c5\u5b8cPyInstaller\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08Mac\u548cLinux\uff09\uff0c\u5bfc\u822a\u81f3\u5305\u542b`my_tkinter_app.py`\u6587\u4ef6\u7684\u6587\u4ef6\u5939\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onefile –windowed my_tkinter_app.py<\/p>\n

“`<\/p>\n

\u8be5\u547d\u4ee4\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n

– `–onefile`\u5c06\u6240\u6709\u4f9d\u8d56\u9879\u4e0ePython\u811a\u672c\u6346\u7ed1\u5728\u4e00\u4e2aexe\u6587\u4ef6\u4e2d\u3002<\/p>\n

– `–windowed`\u6307\u793aPyInstaller\u521b\u5efa\u4e00\u4e2a\u4e0d\u663e\u5728\u7ebf\u7f51\u9875\u751f\u6210exe<\/a>\u793a\u63a7\u5236\u53f0\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u7684GUI\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u7a0d\u7b49\u7247\u523b\uff0c\u60a8\u4f1a\u53d1\u73b0\u751f\u6210\u4e86\u4e00\u4e2a\u540d\u4e3a`dist`\u7684\u65b0\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b`my_tkinter_app.exe`\u6587\u4ef6\u3002\u8fd9\u5c31\u662f\u60a8\u7684Tkinter\u5e94\u7528\u7a0b\u5e8f\u7684exe\u7248\u672c\uff0c\u65e0\u9700\u4efb\u4f55\u989d\u5916\u73af\u5883\u5373\u53ef\u8fd0\u884c\u3002<\/p>\n

\u6ce8\u610f\uff1a\u751f\u6210\u7684exe\u6587\u4ef6\u901a\u5e38\u6bd4\u539f\u59cb\u7684Python\u811a<\/p>\n

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

\u672c\u5927\u5f97\u591a\uff0c\u56e0\u4e3a\u5b83\u5c06Python\u89e3\u91ca\u5668\u548c\u5176\u4ed6\u8fd0\u884c\u65f6\u5e93\u4e0e\u60a8\u7684\u4ee3\u7801\u4e00\u8d77\u6253\u5305\u3002\u540c\u65f6\uff0c\u6839\u636e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u3001Python\u7248\u672c\u548c\u5e93\u7248\u672c\uff0c\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u5982\u679c\u9047\u5230\u4efb\u4f55\u95ee\u9898\uff0c\u8bf7\u67e5\u9605PyInstaller\u7684\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u5c06GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u5e94\u7528\u7a0b\u5e8f\u751f\u6210\u4e3a\u72ec\u7acb\u7684exe\u6587\u4ef6\uff08\u53ef\u6267\u884c\u6587\u4ef6\uff09\u3002\u8fd9\u5bf9\u4e8e\u521b\u5efa\u53ef\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u72ec\u7acb\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5f53\u7528\u6237\u6ca1\u6709\u5b89\u88c5\u6240\u9700\u7684\u8fd0\u884c\u73af\u5883\uff08<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3635,3634,14,186,171],"class_list":["post-1699","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-guiexe","tag-pc","tag-14","tag-186","tag-171"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1699","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\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}