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

GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u662f\u8ba9\u7528\u6237\u4ee5\u56fe\u5f62\u5316\u65b9\u5f0f\u4e0e\u5e94\u7528\u7a0b\u5e8f\u4ea4\u4e92\u7684\u754c\u9762\u3002\u5f00\u53d1\u4e00\u4e2a<\/p>\n

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

\u5177\u6709\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u662f\u8bb8\u591a\u7a0b\u5e8f\u5458\u7684\u5171\u540c\u9700\u6c42\u3002\u5728\u6b64\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e00\u79cd\u65b9\u6cd5\uff0c\u901a\u8fc7\u4f7f\u7528Python\u7f16\u7a0b\u8bed\u8a00\u548cPyInstaller\u5de5\u5177\u6765\u5b9e\u73b0\u3002<\/p>\n

1. \u9009\u62e9\u56fe\u5f62\u7528\u6237\u754c\u9762\u5e93<\/p>\n

\u8981\u521b\u5efa\u5e26\u6709GUI\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u56fe\u5f62\u7528\u6237\u754c\u9762\u5e93\u3002\u6709\u8bb8\u591a\u73b0\u6210\u7684\u5e93\u53ef\u4ee5\u9009\u62e9\uff0c\u5982Tkinter\uff08Python\u5185\u7f6e\uff09\uff0cPyQt\uff0cKivy\u7b49\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Tkinter\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684GUI\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u9996\u5148\uff0c\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u5e26GUI\u7684Python\u5e94\u7528\u7a0b\u5e8f\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u5e26\u6709\u6807\u7b7e\u548c\u6309\u94ae\u7684\u5c0f\u7a97\u53e3\uff1a<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

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

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

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

root.title(‘Sample GUI App’)<\/p>\n

label = tk.Label(root, text=’Welcome to our App!’)<\/p>\n

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

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

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

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

“`<\/p>\n

\u4fdd\u5b58\u6b64\u4ee3\u7801\u4e3a`my_gui_app.pyqt5\u751f\u6210exe\u7f3a\u70b9<\/a>`\u3002<\/p>\n

3. \u5b89\u88c5PyInstaller<\/p>\n

PyInstaller\u662f\u4e00\u4e2a\u5c06Python\u811a\u672c\u8f6c\u6362\u6210\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5b89\u88c5PyInstaller\uff1a<\/p>\n

“`bash<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

4. \u4f7f\u7528PyInstaller\u5c06GUI\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3aEXE<\/p>\n

\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`bash<\/p>\n

pyinstaller –onefile –noconsole my_gui_app.py<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`my_gui_app.exe`\u7684\u5e94\u7528\u7a0b\u5e8f\u3002`–onefile`\u53c2\u6570\u8868\u793a\u5c06\u6240\u6709\u4f9d\u8d56\u9879\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u6587\u4ef6\uff0c`–noconsole`\u53c2\u6570\u8868\u793a\u5728\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\u4e0d\u4f1a\u663e\u793a\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n

5. \u6d4b\u8bd5\u751f\u6210\u7684EXE\u6587\u4ef6<\/p>\n

\u5728`dist`\u76ee\u5f55\u4e2d\uff0c\u4f60\u5c06\u627e\u5230\u751f\u6210\u7684`my_gui_app.exe`\u6587\u4ef6\u3002\u53cc\u51fb\u8fd0\u884c\u6b64\u6587\u4ef6\uff0c\u5c06\u6253\u5f00\u6211\u4eec\u5728\u4ee3\u7801\u4e2d\u521b\u5efa\u7684GUI\u7a97\u53e3\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5728\u5c06EXE\u6587\u4ef6\u5206\u53d1\u7ed9\u5176\u4ed6\u7528\u6237\u65f6\uff0c\u8bf7\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u90fd\u5305\u542b\u5728\u6253\u5305\u7684\u7a0b\u5e8f\u4e2d\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u4f7f\u7528`–onefile`\u53c2\u6570\u786e\u4fdd\u4e86\u8fd9\u4e00\u70b9\u3002\u6b64\u5916\uff0c\u8bf7\u6ce8\u610f\uff0c\u4e3a\u4e86\u5728\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e0atc\u751f\u6210exe\u5931\u8d25<\/a>\u8fd0\u884c\u6b64EXE\u6587\u4ef6\uff0c\u53ef\u80fd\u9700\u8981\u5728\u90a3\u4e9b\u7cfb\u7edf\u4e0a\u91cd\u65b0\u6267\u884cPyInstaller\u751f\u6210\u8fc7\u7a0b\u3002<\/p>\n

\u73b0\u5728\u4f60\u5df2\u7ecf\u77e5\u9053\u5982\u4f55\u5c06GUI\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210EXE\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u63a2\u7d22\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u5982\u6dfb\u52a0\u56fe\u6807\uff0c\u4ee5\u53ca\u5728\u9700\u8981\u65f6\u538b\u7f29\u548c\u4f18\u5316\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

GUI\uff08\u56fe\u5f62\u7528\u6237\u754c\u9762\uff09\u662f\u8ba9\u7528\u6237\u4ee5\u56fe\u5f62\u5316\u65b9\u5f0f\u4e0e\u5e94\u7528\u7a0b\u5e8f\u4ea4\u4e92\u7684\u754c\u9762\u3002\u5f00\u53d1\u4e00\u4e2a\u5177\u6709\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u662f\u8bb8\u591a\u7a0b\u5e8f\u5458\u7684\u5171\u540c\u9700\u6c42\u3002\u5728\u6b64\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e00\u79cd\u65b9\u6cd5\uff0c\u901a\u8fc7\u4f7f\u7528Pyth<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3614,3613,14,171,2732],"class_list":["post-1688","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag--exe","tag-exe","tag-14","tag-171","tag-2732"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1688","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1688"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1688\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}