{"id":7062,"date":"2023-10-19T15:45:21","date_gmt":"2023-10-19T07:45:21","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=7062"},"modified":"2023-10-19T15:45:21","modified_gmt":"2023-10-19T07:45:21","slug":"nanui%e6%89%93%e5%8c%85exe%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/7062\/","title":{"rendered":"nanui\u6253\u5305exe\u64cd\u4f5c\u6d41\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"

nanui\u662f\u4e00\u79cd\u57fa\u4e8ePython\u7684GUI\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002\u5728Python\u4e2d\uff0c\u6709\u5f88\u591a\u6253\u5305\u5de5\u5177\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5176\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u6709pyinstaller\u3001cx_Freeze\u548cpy2exe\u7b49\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pyinstaller\u5c06nanui\u7a0b\u5e8f\u6253\u5305\u6210exe\u6587\u4ef6\u3002<\/p>\n

1. \u5b89\u88c5pyinstaller<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5pyinstaller\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

2. \u7f16\u5199nanui\u7a0b\u5e8f<\/p>\n

\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5047\u8bbe\u4f60\u5df2\u7ecf\u719f\u6089nanui\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5e76\u4e14\u5df2\u7ecf\u7f16\u5199\u597d\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u7a0b\u5e8f\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684GUI\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u6309\u94ae\u548c\u4e00\u4e2a\u6807\u7b7e\u3002\u5f53\u7528\u6237\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6807\u7b7e\u5c06\u4f1a\u663e\u793a\u201cHello, World!\u201d\u3002<\/p>\n

“`python<\/p>\n

import nanui<\/p>\n

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

label.set_text(“Hello, World!”)<\/p>\n

app = nanui.App(<\/p>\n

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

“My App”, “400×300”)<\/p>\n

label = nanui.Label(app, text=”Welcome to My App!”)<\/p>\n

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

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

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

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

“`<\/p>\n

3. \u6253\u5305nanui\u7a0b\u5e8f<\/p>\n

\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onlinux\u5730\u56fe\u8f6f\u4ef6<\/a>efile –windowed app.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c–onefile\u8868\u793a\u5c06\u6240\u6709\u9700\u8981\u7684\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c–windowed\u8868\u793a\u4e0d\u663e\u793a\u547d\u4ee4\u884c\u7a97\u53e3\u3002app.py\u662f\u4f60\u7684Python\u7a0b\u5e8f\u7684\u6587\u4ef6\u540d\u3002<\/p>\n

4. \u8fd0\u884c\u6253\u5305\u540e\u7684\u7a0b\u5e8f<\/p>\n

\u6253\u5305\u5b8c\u6210\u540e\uff0c\u5728dist\u76ee\u5f55\u4e0b\u4f1a\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53cc\u51fb\u8be5\u505a\u5e94\u7528<\/a>\u6587\u4ef6\u5373\u53ef\u8fd0\u884c\u4f60\u7684nanui\u7a0b\u5e8f\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u4f7f\u7528pyinstaller\u6253\u5305nanui\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u51e0\u4e2a\u547d\u4ee4\u5c31\u53ef\u4ee5\u5c06Python\u7a0b\u5e8f\u6253\u5305\u6210exe\u6587\u4ef6\u3002\u5982\u679c\u4f60\u60f3\u8981\u5c06nanui\u7a0b\u5e8f\u5206\u4eab\u7ed9\u5176\u4ed6\u4eba\uff0c\u6253\u5305\u6210exe\u6587\u4ef6\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

nanui\u662f\u4e00\u79cd\u57fa\u4e8ePython\u7684GUI\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002\u5728Python\u4e2d\uff0c\u6709\u5f88\u591a\u6253\u5305\u5de5\u5177\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5176\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u6709pyinstaller\u3001c<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[7137,12618,1622,16,89],"topic":[],"class_list":["post-7062","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-jfxexe","tag-pkgwindowsexe","tag-1622","tag-16","tag-89"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=7062"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7062\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=7062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=7062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=7062"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=7062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}