{"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 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<\/figure>\n<\/p>\n