{"id":2295,"date":"2023-07-03T12:19:16","date_gmt":"2023-07-03T04:19:16","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=2295"},"modified":"2023-07-03T12:19:16","modified_gmt":"2023-07-03T04:19:16","slug":"gui%e7%a8%8b%e5%ba%8f%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%e6%9c%89%e9%82%a3%e4%ba%9b%e7%89%b9%e7%82%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/2295\/","title":{"rendered":"gui\u7a0b\u5e8f\u751f\u6210exe\u6587\u4ef6\u6709\u90a3\u4e9b\u7279\u70b9\uff1f"},"content":{"rendered":"

GUI\u7a0b\u5e8f\u751f\u6210EXE\u6587\u4ef6\uff08\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd\uff09<\/p>\n

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u4e00\u4e2a\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7a0b\u5e8f\u7f16\u8bd1\u6210Windows\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u7684\u8fc7\u7a0b\u548c\u539f\u7406\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709\u5b89\u88c5Python\u89e3\u91ca\u5668\u7684\u7535\u8111\u4e0a\u8f7b\u677e\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n

\u4e00\u3001\u539f\u7406\u7b80\u4ecb<\/p>\n

\u5c06\u56fe\u5f62\u7528\u6237\u754c\u9762\u5e94\u7528\u7a0b\u5e8f\uff08\u5982Python\uff09\u751f\u6210\u4e3a\u72ec\u7acb<\/p>\n

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

\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u4ee5\u8ba9\u7528\u6237\u8f7b\u677e\u90e8\u7f72\u548c\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u53e6\u5916\u5b89\u88c5\u76f8\u5e94\u7684\u8fd0\u884c\u73af\u5883\u3002\u7f16\u8bd1\u8fc7\u7a0b\u5206\u4e3a\u4e24\u90e8\u5206\uff1a<\/p>\n

1. \u6253\u5305\uff08\u5305\u542b\uff09\u7a0b\u5e8f\u6e90\u4ee3\u7801\u3001\u4f9d\u8d56\u7684\u5e93\u6587\u4ef6\u548c\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n

2. \u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5c06Python\u89e3\u91ca\u5668\u4e0e\u7a0b\u5e8f\u4ee3\u7801\u6253\u5305\u5230\u4e00\u8d77\u3002<\/p>\n

\u4e8c\u3001\u5de5\u5177\u4ecb\u7ecd<\/p>\n

\u5728\u5c06GUI\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6\u65f6\uff0c\u6709\u591a\u79cd\u5de5\u5177\u53ef\u4ee5\u9009\u62e9\u3002\u672c\u6587\u5c06\u4ee5Python\u4e3a\u4f8b\uff0c\u63a8\u8350Python\u7684\u7b2c\u4e09\u65b9\u5e93\uff1aPyInstaller\u3002PyInstaller\u652f\u6301Windows\u3001macOS\u548cLinux\uff0c\u975e\u5e38\u9002\u5408\u5c06Python\u7a0b\u5e8f\u5c01\u88c5\u4e3a\u53ef\u5728\u8fd9\u4e9b\u5e73\u53f0\u4e0a\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u4e09\u3001\u6b65\u9aa4\u8be6\u89e3<\/p>\n

\u4ee5\u4f7f\u7528PyInstaller\u751f\u6210\u4e00\u4e2a\u7b80\u5355Python GUI\u7a0b\u5e8f\u4e3a\u4f8b\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n

1. \u786e\u4fdd\u5df2\u5b89\u88c5Python\u5e76\u914d\u7f6e\u597d\u73af\u5883\u53d8\u91cf\u3002<\/p>\n

2. \u5b89\u88c5PyInstaller\u5e93\uff1a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PyInstaller\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

3. \u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u7a0b\u5e8f\u5e76\u4fdd\u5b58\u4e3amy_gui_app.py\uff1a<\/p>\n

“`python<\/p>\n

import tkinter as tk<\/p>\n

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

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

window.title(“My GUI App”)<\/p>\n

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

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

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

if __name__ == “__main__”:<\/p>\n

main()<\/p>\n

“`<\/p>\n

4. \u4f7f\u7528PyInstaller\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6\uff1a<\/p>\n

\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u8f6c\u5230\u5305\u542bmy_gui_app.py\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u8fd0pyqt4\u6253\u5305\u4e3aexe<\/a>\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5c06\u8be5\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u5176\u4e2d `–onefile` \u53c2\u6570\u8868\u793a\u751f\u6210\u5355\u4e2aEXE\u6587\u4ef6\uff0c\u800c`–windowed`\u53c2\u6570\u8868\u793a\u9690\u85cf\u547d\u4ee4\u884c\u7a97\u53e3\u3002\u5982\u679c\u9700\u8981\u5728\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d\u663e\u793a\u4fe1labview \u5c01\u88c5exe<\/a>\u606f\uff0c\u8bf7\u5ffd\u7565\u6b64\u53c2\u6570\u3002<\/p>\n

5. \u751f\u6210\u7684EXE\u6587\u4ef6\u4f4d\u4e8e\u65b0\u521b\u5efa\u7684 “dist” \u76ee\u5f55\u4e2d\u3002\u5c1d\u8bd5\u8fd0\u884c\u8be5\u6587\u4ef6\uff0c\u67e5\u770bGUI\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u679c\u3002<\/p>\n

\u81f3\u6b64\uff0c\u6211\u4eec\u5728Windows\u4e0a\u6210\u529f\u5730\u5c06\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u4e86\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u90e8\u7f72\u6b64\u7c7b\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u53ea\u9700\u53d1\u9001EXE\u6587\u4ef6\u5373\u53ef\uff0c\u65e0\u9700\u5b89\u88c5Python\u6216\u5176\u4ed6\u4f9d\u8d56\u5e93\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

GUI\u7a0b\u5e8f\u751f\u6210EXE\u6587\u4ef6\uff08\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd\uff09\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u4e00\u4e2a\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7a0b\u5e8f\u7f16\u8bd1\u6210Windows\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u7684\u8fc7\u7a0b\u548c\u539f\u7406\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709\u5b89\u88c5Pytho<\/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":[4796,4797,14,171,398],"class_list":["post-2295","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-elementexe","tag-simulinkexe","tag-14","tag-171","tag-398"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/2295","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=2295"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/2295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=2295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=2295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=2295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}