{"id":1825,"date":"2023-06-27T12:19:23","date_gmt":"2023-06-27T04:19:23","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1825\/"},"modified":"2023-06-27T12:19:23","modified_gmt":"2023-06-27T04:19:23","slug":"gui%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%e5%a4%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1825\/","title":{"rendered":"gui\u5982\u4f55\u751f\u6210exe\u6587\u4ef6\u5939\uff1f"},"content":{"rendered":"

\u5728\u6b64\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u5411\u60a8\u4ecb\u7ecd\u5982\u4f55\u5c06\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7a0b\u5e8f\u751f\u6210\u4e3a.exe\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u7684\u7528\u6237\u5728\u6ca1\u6709\u5b89\u88c5\u6240\u9700\u5e93\u6216\u8fd0\u884c\u65f6\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u60a8\u7684\u7a0b\u5e8f\u3002<\/p>\n

\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Python\u4f5c\u4e3a\u5f00\u53d1\u8bed\u8a00\u548cPyInstaller\u4f5c\u4e3a\u751f\u6210.exe\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\uff0c\u6b64\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u8fd9\u662f\u4e00\u4efd\u8be6\u7ec6\u6559\u7a0b\uff0c\u4ece\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u7a0b\u5e8f\u5f00\u59cb\uff0c\u6700\u540e\u5c06\u5176\u8f6c\u6362\u4e3a.exe\u6587\u4ef6\u3002<\/p>\n

\u6b65\u9aa41\uff1a\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u7a0b\u5e8f<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python GUI\u7a0b\u5e8f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Python\u7684Tkinter\u5e93\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amy_gui.py\u7684\u65b0\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u4ee5\u4e0b\u4ee3\u7801\u590d\u5236\u5230\u8be5\u6587\u4ef6\u4e2d\uff1a<\/p>\n

“`python<\/p>\n

\n

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

import tkinter as tk<\/p>\n

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

text = entry.get()<\/p>\n

label.config(text=f”Hello, {text}!”)<\/p>\n

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

root.title(“My Simple GUI”)<\/p>\n

entry = tk.Entry(root, width=50)<\/p>\n

entry.pack(padx=10, pady=10)<\/p>\n

button = tk.Button(root, text=”Enter your name”, command=on_click)<\/p>\n

button.pack(padx=10, pady=10)<\/p>\n

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

label.pack(padx=10, pady=10)<\/p>\n

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

“`<\/p>\n

\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684GUI\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u8f93\u5165\u81ea\u5df1\u7684\u540d\u5b57\uff0c\u7136\u540e\u5355\u51fb\u6309\u94ae\uff0c\u7a0b\u5e8f\u4f1a\u5411\u7528\u6237\u53d1\u51fa\u95ee\u5019\u3002<\/p>\n

\u6b65\u9aa42\uff1a\u5b89\u88c5PyInstaller<\/p>\n

\u5728\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3a.exe\u6587\u4ef6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5PyInstaller\u3002\u5b89\u88c5PyInstaller\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u884c\u3002<\/p>\n

“`bash<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

PyInstaller\u5728\u8fd9\u91cc\u8fdb\u884c\u4ecb\u7ecd\uff1ahttps:\/\/www.pyinstaller.org\/<\/p>\n

\u6b65\u9aa43\uff1a\u5c06Python GUI\u7a0b\u5e8f\u8f6c\u6362\u4e3a.exe\u6587\u4ef6<\/p>\n

\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86PyInstaller\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547dphp\u7f51\u9875\u6253\u5305exe<\/a>\u4ee4\u884c\uff1a<\/p>\n

“`bash<\/p>\n

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

“`<\/p>\n

\u8fd9\u4f1a\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n

– `–onefile`\uff1a\u751f\u6210\u5355\u4e2a.exe\u6587\u4ef6\u3002<\/p>\n

– `–windowed`\uff1a\u9690\u85cf\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u63a7\u5236\u53f0\u7a97\u53e3\u3002(\u82e5\u9700\u8981\u63a7\u5236\u53f0\u53ef\u89c6\u5316\u53ef\u4ee5\u79fb\u9664`–windowed`\u53c2\u6570)<\/p>\n

– `my_gui.py`\uff1a\u8981\u8f6c\u6362\u4e3a.exe\u6587\u4ef6\u7684Pythhtml\u5e94\u7528\u5f00\u53d1<\/a>on\u6e90\u6587\u4ef6\u3002<\/p>\n

\u6267\u884c\u5b8c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0cPyInstaller\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cdist\u201d\u7684\u5b50\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u201cmy_gui.exe\u201d\u3002<\/p>\n

\u6b65\u9aa44\uff1a\u8fd0\u884c\u5e76\u5206\u53d1.exe\u6587\u4ef6<\/p>\n

\u81f3\u6b64\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u751f\u6210\u4e86\u4e00\u4e2a.exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u540d\u4e3a\u201cmy_gui.exe\u201d\u3002\u60a8\u53ef\u4ee5\u53cc\u51fb\u8be5\u6587\u4ef6\u5728Windows\u4e0a\u76f4\u63a5\u8fd0\u884c\uff0c\u6216\u5c06\u5176\u53d1\u9001\u7ed9\u5176\u4ed6\u4eba\u3002<\/p>\n

\u7ed3\u8bba<\/p>\n

\u901a\u8fc7\u672c\u6559\u7a0b\uff0c\u60a8\u5df2\u7ecf\u5b66\u4f1a\u4e86\u5982\u4f55\u5c06Python GUI\u7a0b\u5e8f\u8f6c\u6362\u4e3a.exe\u6587\u4ef6\u3002\u867d\u7136\u6211\u4eec\u4ee5Python\u4e3e\u4f8b\uff0c\u4f46\u7c7b\u4f3c\u7684\u65b9\u6cd5\u53ef\u4ee5\u5e94\u7528\u4e8e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u3002\u73b0\u5728\u60a8\u53ef\u4ee5\u8f7b\u677e\u5c06\u81ea\u5df1\u7684\u5e94\u7528\u7a0b\u5e8f\u53d1\u9001\u7ed9\u4ed6\u4eba\uff0c\u8ba9\u4ed6\u4eec\u5728\u6ca1\u6709\u5b89\u88c5\u4efb\u4f55\u5176\u4ed6\u4f9d\u8d56\u9879\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u6b64\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u5411\u60a8\u4ecb\u7ecd\u5982\u4f55\u5c06\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7a0b\u5e8f\u751f\u6210\u4e3a.exe\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u7684\u7528\u6237\u5728\u6ca1\u6709\u5b89\u88c5\u6240\u9700\u5e93\u6216\u8fd0\u884c\u65f6\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u60a8\u7684\u7a0b\u5e8f\u3002\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528<\/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":[3884,3883,171,398,261],"class_list":["post-1825","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-php","tag-vscodeexe","tag-171","tag-398","tag-261"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1825","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=1825"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}