{"id":1189,"date":"2023-06-26T12:19:24","date_gmt":"2023-06-26T04:19:24","guid":{"rendered":"https:\/\/h5app.yimenapp.cn\/h5app\/?p=1189"},"modified":"2023-06-26T12:19:24","modified_gmt":"2023-06-26T04:19:24","slug":"gui%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/h5app.yimenapp.cn\/h5app\/2023\/ruanjiankf\/1189\/","title":{"rendered":"gui\u5982\u4f55\u751f\u6210exe\u6587\u4ef6\uff1f"},"content":{"rendered":"<p>\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\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u4ee5\u4e0b\u6b65\u9aa4\u5c06\u6307\u5bfc\u60a8\u5b8c\u6210\u5c06Python GUI\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6\u7684\u8fc7\u7a0b\u3002<\/p>\n<p>\u5148\u51b3\u6761\u4ef6\uff1a<\/p>\n<p>1. Python\u73af\u5883\u5df2\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u3002<\/p>\n<p>2. \u9009\u62e9\u4e00\u4e2aPython GUI\u6846\u67b6\uff08tkinter\uff0cPyQt\u7b49\uff09\u3002<\/p>\n<p>\u6b65\u9aa41\uff1a\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Python\u7684tkinter\u5e93\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u5982PyQt\uff0c\u4f46\u6b65\u9aa4\u5c06<a href=\"https:\/\/exe.yimenapp.com\/tool-215.html\">\u5236\u4f5cexe<\/a>\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u5e94\u7528\u7a0b\u5e8f\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`python<\/p>\n<p>import tkinter as tk<\/p>\n<p>def on_click():<\/p>\n<p>    label.config(text=&#8221;\u4f60\u597d\uff0c&#8221; + <a href=\"https:\/\/www.yimenexe.com\/exe-kaifa-3112.html\">exe\u505a\u6210\u7f51\u9875\u7248<\/a>entry.get())<\/p>\n<p>app = tk.Tk()<\/p>\n<p>app.title(&#8220;\u793a\u4f8bGUI&#8221;)<\/p>\n<p>frame = tk.Frame(app)<\/p>\n<p>frame.pack(padx=20, pady=20)<\/p>\n<p>label = tk.Label(frame, text=&#8221;\u8bf7\u8f93\u5165\u4f60\u7684\u540d\u5b57\uff1a&#8221;)<\/p>\n<p>label.pack(side=tk.LEFT)<\/p>\n<p>entry = tk.Entry(frame)<\/p>\n<p>entry.pack(side=tk.LEFT)<\/p>\n<p>button = tk.Button(frame, text=&#8221;\u70b9\u51fb\u6211!&#8221;, command=on_click)<\/p>\n<p>button.pack(side=tk.LEFT, padx=(10, 0))<\/p>\n<p>app.mainloop()<\/p>\n<p>&#8220;`<\/p>\n<p>\u5c06\u4ee5\u4e0a\u4ee3\u7801\u4fdd\u5b58\u4e3a`gui_app.py`\u3002<\/p>\n<p>\u6b65\u9aa42\uff1a\u5b89\u88c5PyInstaller\u5e93<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5PyInstaller\u5e93\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>pip install pyinstaller<\/p>\n<p>&#8220;`<\/p>\n<p>\u6b65\u9aa43\uff1a\u5c06Python GUI\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3aEXE\u6587\u4ef6<\/p>\n<p>\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>&#8220;`<\/p>\n<p>pyinstaller &#8211;onefile &#8211;noconsole gui_app.py<\/p>\n<p>&#8220;`<\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p>&#8211; `&#8211;onefile`: \u751f\u6210\u5355\u4e2aexe\u6587\u4ef6\u3002<\/p>\n<p>&#8211; `&#8211;noconsole`: \u5728Windows\u4e0a\u8fd0\u884c\u7a0b\u5e8f\u65f6\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<p>&#8211; `gui_app.py`: \u8981\u8f6c\u6362\u4e3aEXE\u7684Python\u811a\u672c\u3002<\/p>\n<p>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&#8217;dist&#8217;\u7684\u65b0\u6587\u4ef6\u5939\uff0c<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/21\/11\/14761089989.jpg\" \/><\/figure>\n<\/p>\n<p>\u5728\u6b64\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u540d\u4e3a&#8217;gui_app.exe&#8217;\u7684EXE\u6587\u4ef6\u3002<\/p>\n<p>\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<p>\u539f\u7406\uff1a<\/p>\n<p>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":"<p>\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":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2583,2582,11,81,507],"topic":[],"class_list":["post-1189","post","type-post","status-publish","format-standard","hentry","category-ruanjiankf","tag-javaexe","tag-exe","tag-11","tag-81","tag-507"],"_links":{"self":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/1189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/comments?post=1189"}],"version-history":[{"count":0,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"wp:attachment":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/tags?post=1189"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/topic?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}