{"id":2920,"date":"2025-06-05T13:17:31","date_gmt":"2025-06-05T05:17:31","guid":{"rendered":"https:\/\/blog.kangyue.pro\/?p=2920"},"modified":"2025-07-30T12:17:41","modified_gmt":"2025-07-30T04:17:41","slug":"%e7%94%a8python-ai%e7%94%9f%e6%88%90%e4%b8%80%e4%b8%aa%e6%8f%90%e7%a4%ba%e9%9f%b3%e5%b0%8f%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/blog.kangyue.pro\/?p=2920","title":{"rendered":"\u7528Python + AI\u751f\u6210\u4e00\u4e2a\u63d0\u793a\u97f3\u5c0f\u5de5\u5177"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>python\u751f\u6210\u7684py\u6587\u4ef6\uff0c\u53ef\u8fd0\u884c\u5728\u591a\u4e2a\u5e73\u53f0\uff08\u5982Windows\u3001MacOS\u3001Linux\u7b49\uff09\u3002\u968f\u540e\uff0c\u8fd8\u53ef\u5c06\u8be5\u6587\u4ef6\u751f\u6210\u4e3aexe\u6587\u4ef6\uff0c\u4e0d\u4f9d\u8d56python\u5730\u5728Windows\u4e0b\u8fd0\u884c\u3002<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6210\u54c1\u5de5\u5177<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">V5.0<\/h3>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-87e237dc-53ff-4c0d-88ca-bb2364a6480e\" href=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/07\/\u63d0\u793a\u97f3\u5de5\u51775.0.exe\">\u63d0\u793a\u97f3\u5de5\u51775.0<\/a><a href=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/07\/\u63d0\u793a\u97f3\u5de5\u51775.0.exe\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-87e237dc-53ff-4c0d-88ca-bb2364a6480e\">\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"402\" height=\"383\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-176.png\" alt=\"\" class=\"wp-image-3619\"\/><\/figure>\n\n\n\n<p>\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684\u684c\u9762\u54cd\u94c3\u63d0\u793a\u5de5\u5177\uff0c\u9002\u7528\u4e8e Windows \u7cfb\u7edf\uff0c\u5e2e\u52a9\u4f60\u6309\u65f6\u63d0\u9192\u3001\u5b9a\u65f6\u4e13\u6ce8\u3001\u89c4\u5f8b\u4f11\u606f\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\ud83e\uddf0 \u529f\u80fd\u7279\u8272<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u23f3 <strong>\u5b9a\u65f6\u54cd\u94c3<\/strong>\uff1a\u8bbe\u5b9a\u6bcf\u9694 N \u5206\u949f\u54cd\u94c3\u4e00\u6b21\uff0c\u5171\u54cd\u94c3 M \u6b21\uff1b<\/li>\n\n\n\n<li>\ud83d\udd14 <strong>\u4e24\u79cd\u54cd\u94c3\u6a21\u5f0f<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u6301\u7eed\u54cd\u94c3<\/strong>\uff1a\u4e0d\u505c\u54cd\u94c3\uff0c\u76f4\u5230\u4f60\u79fb\u52a8\u9f20\u6807\u6216\u6572\u51fb\u952e\u76d8\u624d\u4f1a\u91cd\u65b0\u8ba1\u65f6\uff1b<\/li>\n\n\n\n<li><strong>\u54cd\u4e00\u6b21<\/strong>\uff1a\u63d0\u9192\u540e\u81ea\u52a8\u8fdb\u5165\u4e0b\u4e00\u8f6e\u5012\u8ba1\u65f6\uff1b<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\ud83d\udd09 <strong>\u81ea\u5b9a\u4e49\u97f3\u91cf<\/strong>\uff1a\u5185\u7f6e\u7cfb\u7edf\u97f3\u91cf\u8c03\u8282\u529f\u80fd\uff08\u652f\u6301 Windows\uff09\uff1b<\/li>\n\n\n\n<li>\ud83d\udda5\ufe0f <strong>\u7b80\u6d01\u754c\u9762<\/strong>\uff1a\u65e0\u9700\u5b89\u88c5\u3001\u5f00\u7bb1\u5373\u7528\u3001\u754c\u9762\u76f4\u89c2\uff1b<\/li>\n\n\n\n<li>\u2705 <strong>\u517c\u5bb9\u6027\u597d<\/strong>\uff1a\u652f\u6301 Windows 7\/10\/11\uff0c\u8fd0\u884c\u7a33\u5b9a\uff1b<\/li>\n\n\n\n<li>\ud83d\udce6 <strong>\u7eff\u8272\u514d\u5b89\u88c5<\/strong>\uff1a\u53ef\u6267\u884c\u6587\u4ef6\u6216\u6e90\u7801\u7248\u672c\u5747\u53ef\u4f7f\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\ud83e\uddd1\u200d\ud83d\udcbb \u9002\u7528\u573a\u666f<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e13\u6ce8\u5de5\u4f5c \/ \u756a\u8304\u5de5\u4f5c\u6cd5<\/strong><\/li>\n\n\n\n<li><strong>\u5b66\u4e60\u63d0\u9192 \/ \u5bb6\u957f\u5b9a\u65f6\u770b\u62a4<\/strong><\/li>\n\n\n\n<li><strong>\u5b9a\u65f6\u7ad9\u7acb \/ \u5065\u5eb7\u63d0\u793a<\/strong><\/li>\n\n\n\n<li><strong>\u5b9a\u65f6\u559d\u6c34 \/ \u95f4\u6b47\u8fd0\u52a8<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">V1.0<\/h3>\n\n\n\n<p><em>\u65e0\u201c\u5728\u8fd0\u884c\u65f6\u91cd\u65b0\u8ba1\u65f6\u201d\u529f\u80fd\u3002<\/em><\/p>\n\n\n\n<p><em>\u5982\u9700\u91cd\u65b0\u8ba1\u65f6\u529f\u80fd\uff0c\u8bf7\u4f7f\u7528\u672c\u6587python\u4ee3\u7801\u5904\u63d0\u4f9b\u7684\u65b0\u7248\u4ee3\u7801\u3002<\/em><\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-ea4b09df-0b34-4e38-983d-5a991b9fee71\" href=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/\u63d0\u793a\u97f3\u5de5\u5177.exe\">\u63d0\u793a\u97f3\u5de5\u5177<\/a><a href=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/\u63d0\u793a\u97f3\u5de5\u5177.exe\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-ea4b09df-0b34-4e38-983d-5a991b9fee71\">\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"195\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-46.png\" alt=\"\" class=\"wp-image-2935\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u529f\u80fd\u9700\u6c42<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u9694X\u5206\u949f\u53d1\u51fa\u4e00\u6b21\u63d0\u793a\u97f3<\/li>\n\n\n\n<li>\u4e00\u5171\u63d0\u793aY\u6b21<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u7cfb\u7edf\u73af\u5883<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5df2\u5b89\u88c5python\uff0c\u5e76\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/li>\n\n\n\n<li>\u5df2\u5b89\u88c5PyInstaller<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u5b9e\u73b0\u8fc7\u7a0b<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001\u521b\u5efapy\u6587\u4ef6\uff08Python\u4ee3\u7801\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u67d0\u6587\u4ef6\u5939\uff08\u5982\uff1a<code>D:\\python\u7a0b\u5e8f\\\u63d0\u793a\u97f3\u5de5\u5177<\/code>\uff09\u4e0b\u65b0\u5efa\u6587\u672c\u6587\u6863\uff0c\u952e\u5165\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5e76\u5c06\u6587\u4ef6\u540d\u8bbe\u4e3a\u300c<code>\u63d0\u793a\u97f3\u5de5\u5177.py<\/code>\u300d\u3002<\/li>\n\n\n\n<li>\u4e0b\u65b9\u63d0\u4f9b\u4e09\u4e2a\u7248\u672c\u7684\u4ee3\u7801\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\u6700\u65b0\u7248\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>V5.0\uff1a<\/strong><\/p>\n\n\n\t\t<div class='wp-block-bch-code-highlight  align' id='bhcCodeHighlight-b0e16b20-9' data-attributes='{&quot;cId&quot;:&quot;b0e16b20-9&quot;,&quot;language&quot;:&quot;python&quot;,&quot;code&quot;:&quot;# -*- coding: utf-8 -*-\\nimport time\\nimport platform\\nimport os\\nimport threading\\nimport tkinter as tk\\nfrom tkinter import messagebox\\n\\nif platform.system() == &#039;Windows&#039;:\\n    import winsound\\n    from ctypes import POINTER, cast\\n    from comtypes import CLSCTX_ALL, CoInitialize\\n    from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume\\n\\n\\nclass BellApp:\\n    def __init__(self, root):\\n        self.root = root\\n        self.root.title(\\&quot;\\u5b9a\\u65f6\\u54cd\\u94c3\\u5668\\&quot;)\\n        self.root.geometry(\\&quot;400x350\\&quot;)\\n        self.running = False\\n        self.reset_flag = False\\n        self.stop_flag = False\\n\\n        font = (\\&quot;Microsoft YaHei\\&quot;, 12)\\n\\n        self.minutes_var = tk.StringVar(value=\\&quot;5\\&quot;)\\n        self.times_var = tk.StringVar(value=\\&quot;90\\&quot;)\\n\\n        frame = tk.Frame(root)\\n        frame.pack(pady=20)\\n\\n        tk.Label(frame, text=\\&quot;\\u6bcf\\u9694\\&quot;, font=font).grid(row=0, column=0)\\n        tk.Entry(frame, textvariable=self.minutes_var, width=5, font=font).grid(row=0, column=1)\\n        tk.Label(frame, text=\\&quot;\\u5206\\u949f   \\u5171\\u54cd\\u94c3\\&quot;, font=font).grid(row=0, column=2)\\n        tk.Entry(frame, textvariable=self.times_var, width=5, font=font).grid(row=0, column=3)\\n        tk.Label(frame, text=\\&quot;\\u6b21\\&quot;, font=font).grid(row=0, column=4)\\n\\n        btn_frame = tk.Frame(root)\\n        btn_frame.pack(pady=10)\\n\\n        tk.Button(btn_frame, text=\\&quot;\\u5f00\\u59cb\\&quot;, command=self.start, font=font).grid(row=0, column=0, padx=5)\\n        tk.Button(btn_frame, text=\\&quot;\\u91cd\\u65b0\\u5f00\\u59cb\\&quot;, command=self.reset, font=font).grid(row=0, column=1, padx=5)\\n        tk.Button(btn_frame, text=\\&quot;\\u505c\\u6b62\\&quot;, command=self.stop, font=font).grid(row=0, column=2, padx=5)\\n\\n        self.countdown_label = tk.Label(root, text=\\&quot;\\u5f53\\u524d\\u5012\\u8ba1\\u65f6\\uff1a--:--\\&quot;, font=(\\&quot;Microsoft YaHei\\&quot;, 14), fg=\\&quot;blue\\&quot;)\\n        self.countdown_label.pack(pady=10)\\n\\n        self.status_label = tk.Label(root, text=\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a-- \\\/ --\\&quot;, font=(\\&quot;Microsoft YaHei\\&quot;, 12))\\n        self.status_label.pack()\\n\\n        self.volume_var = tk.IntVar(value=100)\\n        volume_frame = tk.Frame(root)\\n        volume_frame.pack(pady=10)\\n        tk.Label(volume_frame, text=\\&quot;\\u97f3\\u91cf\\uff1a\\&quot;, font=font).pack(side=\\&quot;left\\&quot;)\\n        self.volume_slider = tk.Scale(volume_frame, from_=0, to=100, orient=\\&quot;horizontal\\&quot;,\\n                                      variable=self.volume_var, length=200)\\n        self.volume_slider.pack(side=\\&quot;left\\&quot;)\\n\\n        # \\u54cd\\u94c3\\u6a21\\u5f0f\\n        self.mode_var = tk.StringVar(value=\\&quot;continuous\\&quot;)\\n        mode_frame = tk.Frame(root)\\n        mode_frame.pack(pady=5)\\n        tk.Label(mode_frame, text=\\&quot;\\u54cd\\u94c3\\u6a21\\u5f0f\\uff1a\\&quot;, font=font).pack(side=\\&quot;left\\&quot;)\\n        tk.Radiobutton(mode_frame, text=\\&quot;\\u6301\\u7eed\\u54cd\\u94c3\\&quot;, variable=self.mode_var, value=\\&quot;continuous\\&quot;, font=font).pack(side=\\&quot;left\\&quot;)\\n        tk.Radiobutton(mode_frame, text=\\&quot;\\u54cd\\u4e00\\u6b21\\&quot;, variable=self.mode_var, value=\\&quot;once\\&quot;, font=font).pack(side=\\&quot;left\\&quot;)\\n\\n    def set_volume(self, vol_percent):\\n        if platform.system() != &#039;Windows&#039;:\\n            return\\n        try:\\n            CoInitialize()\\n            devices = AudioUtilities.GetSpeakers()\\n            interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)\\n            volume = cast(interface, POINTER(IAudioEndpointVolume))\\n            vol = float(vol_percent) \\\/ 100.0\\n            volume.SetMasterVolumeLevelScalar(vol, None)\\n        except Exception as e:\\n            print(f\\&quot;[\\u97f3\\u91cf\\u8c03\\u8282\\u5931\\u8d25] {e}\\&quot;)\\n\\n    def start(self):\\n        if self.running:\\n            return\\n        try:\\n            self.minutes = float(self.minutes_var.get())\\n            self.total_times = int(self.times_var.get())\\n        except ValueError:\\n            messagebox.showerror(\\&quot;\\u683c\\u5f0f\\u9519\\u8bef\\&quot;, \\&quot;\\u8bf7\\u8f93\\u5165\\u6709\\u6548\\u7684\\u6570\\u5b57\\&quot;)\\n            return\\n\\n        self.current_count = 1\\n        self.running = True\\n        self.stop_flag = False\\n        self.reset_flag = False\\n\\n        threading.Thread(target=self.run_timer, daemon=True).start()\\n\\n    def reset(self):\\n        if not self.running:\\n            return\\n        self.reset_flag = True\\n\\n    def stop(self):\\n        self.running = False\\n        self.stop_flag = True\\n        self.countdown_label.config(text=\\&quot;\\u5df2\\u505c\\u6b62\\&quot;)\\n        self.status_label.config(text=\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a-- \\\/ --\\&quot;)\\n\\n    def play_sound(self, index):\\n        vol = self.volume_var.get()\\n        self.set_volume(vol)\\n\\n        if platform.system() == &#039;Windows&#039;:\\n            if index &lt;= 30:\\n                winsound.Beep(800, 300)\\n                winsound.Beep(1000, 300)\\n            elif index &lt;= 60:\\n                winsound.Beep(600, 200)\\n                winsound.Beep(1100, 400)\\n            else:\\n                winsound.Beep(900, 150)\\n                winsound.Beep(1200, 150)\\n                winsound.Beep(1500, 150)\\n        else:\\n            os.system(&#039;echo -e \\&quot;\\\\\\\\a\\&quot;&#039;)\\n\\n    def has_user_activity(self):\\n        if platform.system() != &#039;Windows&#039;:\\n            return True\\n\\n        import ctypes\\n        class LASTINPUTINFO(ctypes.Structure):\\n            _fields_ = [(\\&quot;cbSize\\&quot;, ctypes.c_uint), (\\&quot;dwTime\\&quot;, ctypes.c_uint)]\\n\\n        last_input_info = LASTINPUTINFO()\\n        last_input_info.cbSize = ctypes.sizeof(LASTINPUTINFO)\\n        ctypes.windll.user32.GetLastInputInfo(ctypes.byref(last_input_info))\\n        elapsed = ctypes.windll.kernel32.GetTickCount() - last_input_info.dwTime\\n        return elapsed &lt; 2000\\n\\n    def run_timer(self):\\n        while self.current_count &lt;= self.total_times and not self.stop_flag:\\n            self.status_label.config(text=f\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a{self.current_count} \\\/ {self.total_times}\\&quot;)\\n            seconds = int(self.minutes * 60)\\n\\n            for remaining in range(seconds, 0, -1):\\n                if self.reset_flag or self.stop_flag:\\n                    break\\n                mins, secs = divmod(remaining, 60)\\n                self.countdown_label.config(text=f\\&quot;\\u5f53\\u524d\\u5012\\u8ba1\\u65f6\\uff1a{mins:02d}:{secs:02d}\\&quot;)\\n                time.sleep(1)\\n\\n            if self.reset_flag:\\n                self.current_count = 1\\n                self.reset_flag = False\\n                continue\\n\\n            if not self.stop_flag:\\n                if self.mode_var.get() == \\&quot;continuous\\&quot;:\\n                    self.countdown_label.config(text=\\&quot;\\ud83d\\udd14 \\u6301\\u7eed\\u54cd\\u94c3\\u4e2d\\&quot;)\\n                    while not self.has_user_activity() and not self.stop_flag and not self.reset_flag:\\n                        self.play_sound(self.current_count)\\n                        time.sleep(1.5)\\n                    if not self.stop_flag and not self.reset_flag:\\n                        self.countdown_label.config(text=\\&quot;\\u23f1 \\u91cd\\u65b0\\u8ba1\\u65f6\\&quot;)\\n                else:\\n                    self.countdown_label.config(text=\\&quot;\\ud83d\\udd14 \\u54cd\\u94c3\\u4e2d\\&quot;)\\n                    self.play_sound(self.current_count)\\n                    time.sleep(2)\\n\\n                self.current_count += 1\\n\\n        self.running = False\\n        if not self.stop_flag:\\n            self.countdown_label.config(text=\\&quot;\\u2705 \\u5b8c\\u6210\\&quot;)\\n\\n\\nif __name__ == \\&quot;__main__\\&quot;:\\n    try:\\n        root = tk.Tk()\\n        app = BellApp(root)\\n        root.mainloop()\\n    except Exception as e:\\n        import traceback\\n        with open(\\&quot;error_log.txt\\&quot;, \\&quot;w\\&quot;, encoding=\\&quot;utf-8\\&quot;) as f:\\n            traceback.print_exc(file=f)\\n        messagebox.showerror(\\&quot;\\u7a0b\\u5e8f\\u5d29\\u6e83\\&quot;, f\\&quot;\\u9519\\u8bef\\u4fe1\\u606f\\u5df2\\u4fdd\\u5b58\\u5230 error_log.txt\\\\n{str(e)}\\&quot;)\\n&quot;,&quot;codeTypo&quot;:{&quot;desktop&quot;:9,&quot;tablet&quot;:15,&quot;mobile&quot;:14},&quot;height&quot;:{&quot;desktop&quot;:&quot;300px&quot;,&quot;tablet&quot;:&quot;0px&quot;,&quot;mobile&quot;:&quot;0px&quot;},&quot;align&quot;:&quot;&quot;,&quot;lineNumbers&quot;:true,&quot;theme&quot;:&quot;default&quot;,&quot;clipBoard&quot;:true,&quot;wordWrap&quot;:true,&quot;width&quot;:{&quot;desktop&quot;:&quot;100%&quot;,&quot;tablet&quot;:&quot;100%&quot;,&quot;mobile&quot;:&quot;100%&quot;},&quot;padding&quot;:{&quot;top&quot;:&quot;0px&quot;,&quot;right&quot;:&quot;0px&quot;,&quot;bottom&quot;:&quot;0px&quot;,&quot;left&quot;:&quot;0px&quot;},&quot;background&quot;:{&quot;color&quot;:&quot;#d3cfcf42&quot;},&quot;layout&quot;:{&quot;align&quot;:&quot;left&quot;},&quot;border&quot;:{&quot;color&quot;:&quot;#000&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;width&quot;:&quot;0px&quot;},&quot;shadow&quot;:[],&quot;alignment&quot;:&quot;center&quot;,&quot;clipBoardColors&quot;:{&quot;color&quot;:&quot;#fff&quot;,&quot;bg&quot;:&quot;#00000024&quot;}}'><\/div>\r\n\r\n\t\t\n\n\n<p><strong>V3.0\uff1a<\/strong><\/p>\n\n\n\n<p><em>\u56fe\u5f62\u5316\u754c\u9762\uff0c\u4ee5\u53ca\u97f3\u91cf\u8c03\u8282<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"402\" height=\"413\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-149.png\" alt=\"\" class=\"wp-image-3377\" style=\"width:620px;height:auto\"\/><\/figure>\n\n\n\n<p>\u63d0\u793a\uff1a\u9700\u8981\u5b89\u88c5\u97f3\u91cf\u63a7\u5236\u5e93\u3002\u8bf7\u5728cmd\u4e2d\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>pip install pycaw comtypes<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5b8c\u6574python\u4ee3\u7801\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1073\" height=\"424\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-150.png\" alt=\"\" class=\"wp-image-3379\" srcset=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-150.png 1073w, https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-150-768x303.png 768w\" sizes=\"auto, (max-width: 1073px) 100vw, 1073px\" \/><\/figure>\n\n\n\t\t<div class='wp-block-bch-code-highlight  align' id='bhcCodeHighlight-47a77bec-b' data-attributes='{&quot;cId&quot;:&quot;47a77bec-b&quot;,&quot;language&quot;:&quot;python&quot;,&quot;code&quot;:&quot;import time\\nimport platform\\nimport os\\nimport sys\\nimport threading\\nimport tkinter as tk\\nfrom tkinter import messagebox\\n\\nif platform.system() == &#039;Windows&#039;:\\n    import winsound\\n    from ctypes import POINTER, cast\\n    from comtypes import CLSCTX_ALL\\n    from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume\\n\\n\\nclass BellApp:\\n    def __init__(self, root):\\n        self.root = root\\n        self.root.title(\\&quot;\\u5b9a\\u65f6\\u54cd\\u94c3\\u5668\\&quot;)\\n        self.root.geometry(\\&quot;400x380\\&quot;)\\n        self.running = False\\n        self.reset_flag = False\\n        self.stop_flag = False\\n\\n        font = (\\&quot;Microsoft YaHei\\&quot;, 12)\\n\\n        self.minutes_var = tk.StringVar(value=\\&quot;5\\&quot;)\\n        self.times_var = tk.StringVar(value=\\&quot;90\\&quot;)\\n\\n        frame = tk.Frame(root)\\n        frame.pack(pady=20)\\n\\n        tk.Label(frame, text=\\&quot;\\u6bcf\\u9694\\&quot;, font=font).grid(row=0, column=0)\\n        tk.Entry(frame, textvariable=self.minutes_var, width=5, font=font).grid(row=0, column=1)\\n        tk.Label(frame, text=\\&quot;\\u5206\\u949f   \\u5171\\u54cd\\u94c3\\&quot;, font=font).grid(row=0, column=2)\\n        tk.Entry(frame, textvariable=self.times_var, width=5, font=font).grid(row=0, column=3)\\n        tk.Label(frame, text=\\&quot;\\u6b21\\&quot;, font=font).grid(row=0, column=4)\\n\\n        btn_frame = tk.Frame(root)\\n        btn_frame.pack(pady=10)\\n\\n        tk.Button(btn_frame, text=\\&quot;\\u5f00\\u59cb\\&quot;, command=self.start, font=font).grid(row=0, column=0, padx=5)\\n        tk.Button(btn_frame, text=\\&quot;\\u91cd\\u65b0\\u5f00\\u59cb\\&quot;, command=self.reset, font=font).grid(row=0, column=1, padx=5)\\n        tk.Button(btn_frame, text=\\&quot;\\u505c\\u6b62\\&quot;, command=self.stop, font=font).grid(row=0, column=2, padx=5)\\n\\n        self.countdown_label = tk.Label(root, text=\\&quot;\\u5f53\\u524d\\u5012\\u8ba1\\u65f6\\uff1a--:--\\&quot;, font=(\\&quot;Microsoft YaHei\\&quot;, 14), fg=\\&quot;blue\\&quot;)\\n        self.countdown_label.pack(pady=10)\\n\\n        self.status_label = tk.Label(root, text=\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a-- \\\/ --\\&quot;, font=(\\&quot;Microsoft YaHei\\&quot;, 12))\\n        self.status_label.pack()\\n\\n        # \\u97f3\\u91cf\\u8c03\\u8282\\u6ed1\\u5757\\n        self.volume_var = tk.IntVar(value=100)\\n        volume_frame = tk.Frame(root)\\n        volume_frame.pack(pady=10)\\n        tk.Label(volume_frame, text=\\&quot;\\u97f3\\u91cf\\uff1a\\&quot;, font=font).pack(side=\\&quot;left\\&quot;)\\n        self.volume_slider = tk.Scale(volume_frame, from_=0, to=100, orient=\\&quot;horizontal\\&quot;,\\n                                      variable=self.volume_var, length=200)\\n        self.volume_slider.pack(side=\\&quot;left\\&quot;)\\n\\n    def set_volume(self, vol_percent):\\n        \\&quot;\\&quot;\\&quot;\\u8bbe\\u7f6e\\u7cfb\\u7edf\\u97f3\\u91cf\\uff08\\u4ec5\\u9650Windows\\uff09\\&quot;\\&quot;\\&quot;\\n        if platform.system() != &#039;Windows&#039;:\\n            return\\n        try:\\n            devices = AudioUtilities.GetSpeakers()\\n            interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)\\n            volume = cast(interface, POINTER(IAudioEndpointVolume))\\n            vol = float(vol_percent) \\\/ 100.0\\n            volume.SetMasterVolumeLevelScalar(vol, None)\\n        except Exception as e:\\n            print(f\\&quot;[\\u97f3\\u91cf\\u8c03\\u8282\\u5931\\u8d25] {e}\\&quot;)\\n\\n    def start(self):\\n        if self.running:\\n            return\\n        try:\\n            self.minutes = float(self.minutes_var.get())\\n            self.total_times = int(self.times_var.get())\\n        except ValueError:\\n            messagebox.showerror(\\&quot;\\u683c\\u5f0f\\u9519\\u8bef\\&quot;, \\&quot;\\u8bf7\\u8f93\\u5165\\u6709\\u6548\\u7684\\u6570\\u5b57\\&quot;)\\n            return\\n\\n        self.current_count = 1\\n        self.running = True\\n        self.stop_flag = False\\n        self.reset_flag = False\\n\\n        threading.Thread(target=self.run_timer, daemon=True).start()\\n\\n    def reset(self):\\n        if not self.running:\\n            return\\n        self.reset_flag = True\\n\\n    def stop(self):\\n        self.running = False\\n        self.stop_flag = True\\n        self.countdown_label.config(text=\\&quot;\\u5df2\\u505c\\u6b62\\&quot;)\\n        self.status_label.config(text=\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a-- \\\/ --\\&quot;)\\n\\n    def play_sound(self, index):\\n        vol = self.volume_var.get()\\n        self.set_volume(vol)\\n\\n        if platform.system() == &#039;Windows&#039;:\\n            if index &lt;= 30:\\n                winsound.Beep(800, 300)\\n                winsound.Beep(1000, 300)\\n            elif index &lt;= 60:\\n                winsound.Beep(600, 200)\\n                winsound.Beep(1100, 400)\\n            else:\\n                winsound.Beep(900, 150)\\n                winsound.Beep(1200, 150)\\n                winsound.Beep(1500, 150)\\n        else:\\n            os.system(&#039;echo -e \\&quot;\\\\\\\\a\\&quot;&#039;)\\n\\n    def run_timer(self):\\n        while self.current_count &lt;= self.total_times and not self.stop_flag:\\n            self.status_label.config(text=f\\&quot;\\u5f53\\u524d\\u6b21\\u6570\\uff1a{self.current_count} \\\/ {self.total_times}\\&quot;)\\n\\n            seconds = int(self.minutes * 60)\\n            for remaining in range(seconds, 0, -1):\\n                if self.reset_flag or self.stop_flag:\\n                    break\\n                mins, secs = divmod(remaining, 60)\\n                self.countdown_label.config(text=f\\&quot;\\u5f53\\u524d\\u5012\\u8ba1\\u65f6\\uff1a{mins:02d}:{secs:02d}\\&quot;)\\n                time.sleep(1)\\n\\n            if self.reset_flag:\\n                self.current_count = 1\\n                self.reset_flag = False\\n                continue\\n\\n            if not self.stop_flag:\\n                self.countdown_label.config(text=\\&quot;\\ud83d\\udd14 \\u54cd\\u94c3\\u4e2d\\&quot;)\\n                self.play_sound(self.current_count)\\n                self.current_count += 1\\n\\n        self.running = False\\n        if not self.stop_flag:\\n            self.countdown_label.config(text=\\&quot;\\u2705 \\u5b8c\\u6210\\&quot;)\\n\\nif __name__ == \\&quot;__main__\\&quot;:\\n    root = tk.Tk()\\n    app = BellApp(root)\\n    root.mainloop()\\n&quot;,&quot;theme&quot;:&quot;porple&quot;,&quot;codeTypo&quot;:{&quot;desktop&quot;:9,&quot;tablet&quot;:15,&quot;mobile&quot;:14},&quot;height&quot;:{&quot;desktop&quot;:&quot;200px&quot;,&quot;tablet&quot;:&quot;0px&quot;,&quot;mobile&quot;:&quot;0px&quot;},&quot;background&quot;:{&quot;color&quot;:&quot;rgba(0, 0, 0, 0.26)&quot;,&quot;type&quot;:&quot;solid&quot;,&quot;gradient&quot;:&quot;linear-gradient(90deg,#4527a4 0%,#8344c5 100%)&quot;},&quot;align&quot;:&quot;&quot;,&quot;lineNumbers&quot;:true,&quot;clipBoard&quot;:true,&quot;wordWrap&quot;:true,&quot;width&quot;:{&quot;desktop&quot;:&quot;100%&quot;,&quot;tablet&quot;:&quot;100%&quot;,&quot;mobile&quot;:&quot;100%&quot;},&quot;padding&quot;:{&quot;top&quot;:&quot;0px&quot;,&quot;right&quot;:&quot;0px&quot;,&quot;bottom&quot;:&quot;0px&quot;,&quot;left&quot;:&quot;0px&quot;},&quot;layout&quot;:{&quot;align&quot;:&quot;left&quot;},&quot;border&quot;:{&quot;color&quot;:&quot;#000&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;width&quot;:&quot;0px&quot;},&quot;shadow&quot;:[],&quot;alignment&quot;:&quot;center&quot;,&quot;clipBoardColors&quot;:{&quot;color&quot;:&quot;#fff&quot;,&quot;bg&quot;:&quot;#00000024&quot;}}'><\/div>\r\n\r\n\t\t\n\n\n<p><strong>V2.0\uff1a<\/strong><\/p>\n\n\n\n<p><em>\u8fc7\u7a0b\u4e2d\u952e\u51651\u5e76\u56de\u8f66\uff0c\u53ef\u91cd\u65b0\u8ba1\u65f6<\/em><\/p>\n\n\n\t\t<div class='wp-block-bch-code-highlight  align' id='bhcCodeHighlight-390f4f4b-d' data-attributes='{&quot;cId&quot;:&quot;390f4f4b-d&quot;,&quot;language&quot;:&quot;python&quot;,&quot;code&quot;:&quot;import time\\nimport platform\\nimport os\\nimport sys\\nimport threading\\n\\n# \\u63a7\\u5236\\u53d8\\u91cf\\uff1a\\u91cd\\u7f6e\\u6216\\u9000\\u51fa\\ncontrol = {\\&quot;reset\\&quot;: False, \\&quot;exit\\&quot;: False}\\n\\ndef play_sound(index):\\n    if platform.system() == &#039;Windows&#039;:\\n        import winsound\\n        if index &lt;= 30:\\n            winsound.Beep(800, 300)\\n            winsound.Beep(1000, 300)\\n        elif index &lt;= 60:\\n            winsound.Beep(600, 200)\\n            winsound.Beep(1100, 400)\\n        else:\\n            winsound.Beep(900, 150)\\n            winsound.Beep(1200, 150)\\n            winsound.Beep(1500, 150)\\n    else:\\n        os.system(&#039;echo -e \\&quot;\\\\\\\\a\\&quot;&#039;)\\n\\ndef input_listener():\\n    \\&quot;\\&quot;\\&quot;\\u76d1\\u542c\\u7528\\u6237\\u8f93\\u5165\\&quot;\\&quot;\\&quot;\\n    while True:\\n        key = input().strip().lower()\\n        if key == &#039;1&#039;:\\n            control[\\&quot;reset\\&quot;] = True\\n        elif key == &#039;q&#039;:\\n            control[\\&quot;exit\\&quot;] = True\\n            break\\n\\ndef countdown_timer(minutes, total_times):\\n    interval = minutes * 60\\n    current_index = 1\\n\\n    print(\\&quot;\\u63d0\\u793a\\uff1a\\u8fd0\\u884c\\u8fc7\\u7a0b\\u4e2d\\u8f93\\u5165 1 \\u53ef\\u91cd\\u65b0\\u5f00\\u59cb\\uff0c\\u8f93\\u5165 q \\u53ef\\u9000\\u51fa\\u3002\\\\n\\&quot;)\\n\\n    while current_index &lt;= total_times:\\n        print(f\\&quot;\\\\n\\u23f3 \\u7b2c {current_index} \\u6b21\\u54cd\\u94c3\\u5c06\\u5728 {minutes} \\u5206\\u949f\\u540e\\u54cd\\u8d77...\\&quot;)\\n\\n        for remaining in range(interval, 0, -1):\\n            if control[\\&quot;exit\\&quot;]:\\n                print(\\&quot;\\\\n\\ud83d\\udeaa \\u5df2\\u9000\\u51fa\\u7a0b\\u5e8f\\u3002\\&quot;)\\n                return\\n            if control[\\&quot;reset\\&quot;]:\\n                print(\\&quot;\\\\n\\ud83d\\udd01 \\u68c0\\u6d4b\\u5230\\u8f93\\u5165 1\\uff0c\\u91cd\\u65b0\\u5f00\\u59cb\\u8ba1\\u65f6\\uff08\\u4ece\\u7b2c 1 \\u6b21\\uff09...\\&quot;)\\n                control[\\&quot;reset\\&quot;] = False\\n                current_index = 1\\n                break\\n\\n            mins, secs = divmod(remaining, 60)\\n            print(f\\&quot;  \\u5012\\u8ba1\\u65f6: {mins:02d}:{secs:02d}\\&quot;, end=&#039;\\\\r&#039;)\\n            sys.stdout.flush()\\n            time.sleep(1)\\n        else:\\n            print(f\\&quot;\\\\n\\ud83d\\udd14 \\u7b2c {current_index} \\u6b21\\u54cd\\u94c3\\uff01\\&quot;)\\n            play_sound(current_index)\\n            current_index += 1\\n\\n    print(\\&quot;\\\\n\\u2705 \\u5168\\u90e8\\u54cd\\u94c3\\u7ed3\\u675f\\uff01\\&quot;)\\n\\nif __name__ == \\&quot;__main__\\&quot;:\\n    try:\\n        inp = input(\\&quot;\\u8bf7\\u8f93\\u5165\\u2018\\u5206\\u949f\\u6570 \\u6b21\\u6570\\u2019\\uff0c\\u4f8b\\u5982 \\u20185 90\\u2019\\uff08\\u76f4\\u63a5\\u56de\\u8f66\\u4f7f\\u7528\\u9ed8\\u8ba4\\u503c 5 \\u5206\\u949f \\\/ 90 \\u6b21\\uff09: \\&quot;).strip()\\n        if inp:\\n            parts = inp.split()\\n            if len(parts) &gt;= 2:\\n                minutes = int(parts[0])\\n                total_times = int(parts[1])\\n            else:\\n                raise ValueError(\\&quot;\\u8f93\\u5165\\u683c\\u5f0f\\u4e0d\\u6b63\\u786e\\u3002\\&quot;)\\n        else:\\n            minutes = 5\\n            total_times = 90\\n    except Exception:\\n        print(\\&quot;\\u26a0\\ufe0f \\u8f93\\u5165\\u5f02\\u5e38\\uff0c\\u4f7f\\u7528\\u9ed8\\u8ba4\\u8bbe\\u7f6e\\uff1a5 \\u5206\\u949f \\\/ 90 \\u6b21\\&quot;)\\n        minutes = 5\\n        total_times = 90\\n\\n    # \\u542f\\u52a8\\u76d1\\u542c\\u7ebf\\u7a0b\\uff08\\u5b88\\u62a4\\u7ebf\\u7a0b\\uff09\\n    listener_thread = threading.Thread(target=input_listener, daemon=True)\\n    listener_thread.start()\\n\\n    countdown_timer(minutes, total_times)\\n&quot;,&quot;theme&quot;:&quot;porple&quot;,&quot;codeTypo&quot;:{&quot;desktop&quot;:9,&quot;tablet&quot;:15,&quot;mobile&quot;:14},&quot;height&quot;:{&quot;desktop&quot;:&quot;200px&quot;,&quot;tablet&quot;:&quot;0px&quot;,&quot;mobile&quot;:&quot;0px&quot;},&quot;background&quot;:{&quot;color&quot;:&quot;rgba(0, 0, 0, 0.26)&quot;,&quot;type&quot;:&quot;solid&quot;,&quot;gradient&quot;:&quot;linear-gradient(90deg,#4527a4 0%,#8344c5 100%)&quot;},&quot;align&quot;:&quot;&quot;,&quot;lineNumbers&quot;:true,&quot;clipBoard&quot;:true,&quot;wordWrap&quot;:true,&quot;width&quot;:{&quot;desktop&quot;:&quot;100%&quot;,&quot;tablet&quot;:&quot;100%&quot;,&quot;mobile&quot;:&quot;100%&quot;},&quot;padding&quot;:{&quot;top&quot;:&quot;0px&quot;,&quot;right&quot;:&quot;0px&quot;,&quot;bottom&quot;:&quot;0px&quot;,&quot;left&quot;:&quot;0px&quot;},&quot;layout&quot;:{&quot;align&quot;:&quot;left&quot;},&quot;border&quot;:{&quot;color&quot;:&quot;#000&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;width&quot;:&quot;0px&quot;},&quot;shadow&quot;:[],&quot;alignment&quot;:&quot;center&quot;,&quot;clipBoardColors&quot;:{&quot;color&quot;:&quot;#fff&quot;,&quot;bg&quot;:&quot;#00000024&quot;}}'><\/div>\r\n\r\n\t\t\n\n\n<p><strong>V1.0\uff1a<\/strong><\/p>\n\n\n\t\t<div class='wp-block-bch-code-highlight  align' id='bhcCodeHighlight-1c0b5315-c' data-attributes='{&quot;cId&quot;:&quot;1c0b5315-c&quot;,&quot;language&quot;:&quot;python&quot;,&quot;code&quot;:&quot;import time\\nimport platform\\nimport os\\nimport sys\\n\\ndef play_sound(index):\\n    \\&quot;\\&quot;\\&quot;\\u6839\\u636e\\u6b21\\u6570\\u51b3\\u5b9a\\u63d0\\u793a\\u97f3\\u9891\\u7387\\u548c\\u65f6\\u957f\\&quot;\\&quot;\\&quot;\\n    if platform.system() == &#039;Windows&#039;:\\n        import winsound\\n        if (index - 1) % 30 == 0 and index &gt; 1:  # \\u7b2c31\\u300161\\u300191\\u2026\\u2026\\n            winsound.Beep(1600, 1200)  # \\u7b2c\\u4e8c\\u79cd\\u63d0\\u793a\\u97f3\\n        else:\\n            winsound.Beep(1000, 800)  # \\u7b2c\\u4e00\\u79cd\\u63d0\\u793a\\u97f3\\n    else:\\n        # \\u7b80\\u5355\\u8de8\\u5e73\\u53f0\\u5904\\u7406\\uff08Linux \\\/ macOS\\uff09\\n        if (index - 1) % 30 == 0 and index &gt; 1:\\n            os.system(&#039;echo -e \\&quot;\\\\\\\\a\\&quot;&#039;)  # \\u7b2c\\u4e8c\\u79cd\\u63d0\\u793a\\u97f3\\n        else:\\n            os.system(&#039;echo -e \\&quot;\\\\\\\\a\\&quot;&#039;)  # \\u7b2c\\u4e00\\u79cd\\u63d0\\u793a\\u97f3\\n\\ndef countdown_timer(minutes, total_times):\\n    interval = minutes * 60\\n    for i in range(1, total_times + 1):\\n        print(f\\&quot;\\\\n\\u23f3 \\u7b2c {i} \\u6b21\\u54cd\\u94c3\\u5c06\\u5728 {minutes} \\u5206\\u949f\\u540e\\u54cd\\u8d77...\\&quot;)\\n        for remaining in range(interval, 0, -1):\\n            mins, secs = divmod(remaining, 60)\\n            print(f\\&quot;  \\u5012\\u8ba1\\u65f6: {mins:02d}:{secs:02d}\\&quot;, end=&#039;\\\\r&#039;)\\n            sys.stdout.flush()\\n            time.sleep(1)\\n        print(f\\&quot;\\\\n\\ud83d\\udd14 \\u7b2c {i} \\u6b21\\u54cd\\u94c3\\uff01\\&quot;)\\n        play_sound(i)\\n    print(\\&quot;\\\\n\\u2705 \\u5168\\u90e8\\u54cd\\u94c3\\u7ed3\\u675f\\uff01\\&quot;)\\n\\nif __name__ == \\&quot;__main__\\&quot;:\\n    try:\\n        inp = input(\\&quot;\\u8bf7\\u8f93\\u5165\\u2018\\u5206\\u949f\\u6570 \\u6b21\\u6570\\u2019\\uff0c\\u4f8b\\u5982 \\u20183 60\\u2019\\uff08\\u76f4\\u63a5\\u56de\\u8f66\\u4f7f\\u7528\\u9ed8\\u8ba4\\u503c 3 \\u5206\\u949f \\\/ 60 \\u6b21\\uff09: \\&quot;).strip()\\n        if inp:\\n            parts = inp.split()\\n            if len(parts) &gt;= 2:\\n                minutes = int(parts[0])\\n                total_times = int(parts[1])\\n            else:\\n                raise ValueError(\\&quot;\\u8f93\\u5165\\u683c\\u5f0f\\u4e0d\\u6b63\\u786e\\u3002\\&quot;)\\n        else:\\n            minutes = 3\\n            total_times = 60\\n    except Exception as e:\\n        print(\\&quot;\\u26a0\\ufe0f \\u8f93\\u5165\\u5f02\\u5e38\\uff0c\\u4f7f\\u7528\\u9ed8\\u8ba4\\u8bbe\\u7f6e\\uff1a3 \\u5206\\u949f \\\/ 60 \\u6b21\\&quot;)\\n        minutes = 3\\n        total_times = 60\\n\\n    countdown_timer(minutes, total_times)\\n&quot;,&quot;theme&quot;:&quot;porple&quot;,&quot;codeTypo&quot;:{&quot;desktop&quot;:9,&quot;tablet&quot;:15,&quot;mobile&quot;:14},&quot;height&quot;:{&quot;desktop&quot;:&quot;200px&quot;,&quot;tablet&quot;:&quot;0px&quot;,&quot;mobile&quot;:&quot;0px&quot;},&quot;background&quot;:{&quot;color&quot;:&quot;rgba(0, 0, 0, 0.26)&quot;,&quot;type&quot;:&quot;solid&quot;,&quot;gradient&quot;:&quot;linear-gradient(90deg,#4527a4 0%,#8344c5 100%)&quot;},&quot;align&quot;:&quot;&quot;,&quot;lineNumbers&quot;:true,&quot;clipBoard&quot;:true,&quot;wordWrap&quot;:true,&quot;width&quot;:{&quot;desktop&quot;:&quot;100%&quot;,&quot;tablet&quot;:&quot;100%&quot;,&quot;mobile&quot;:&quot;100%&quot;},&quot;padding&quot;:{&quot;top&quot;:&quot;0px&quot;,&quot;right&quot;:&quot;0px&quot;,&quot;bottom&quot;:&quot;0px&quot;,&quot;left&quot;:&quot;0px&quot;},&quot;layout&quot;:{&quot;align&quot;:&quot;left&quot;},&quot;border&quot;:{&quot;color&quot;:&quot;#000&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;width&quot;:&quot;0px&quot;},&quot;shadow&quot;:[],&quot;alignment&quot;:&quot;center&quot;,&quot;clipBoardColors&quot;:{&quot;color&quot;:&quot;#fff&quot;,&quot;bg&quot;:&quot;#00000024&quot;}}'><\/div>\r\n\r\n\t\t\n\n\n<p>*<em>\u4ee5\u4e0a\u4ee3\u7801\uff0c\u7531ChatGPT\u63d0\u4f9b\u3002<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"617\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-40.png\" alt=\"\" class=\"wp-image-2924\"\/><\/figure>\n\n\n\n<p>\u6b64\u65f6\uff0c\u53cc\u51fb\u8fd0\u884cpy\u6587\u4ef6\uff0c\u5373\u53ef\u5b9e\u73b0\u63d0\u793a\u97f3\u529f\u80fd\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"279\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-41.png\" alt=\"\" class=\"wp-image-2925\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001\u521b\u5efa\u53ef\u6267\u884c\u7684exe\u6587\u4ef6<\/h3>\n\n\n\n<p>\u4e3a\u4e86\u4f7f\u8be5\u5de5\u5177\u53ef\u5728\u6ca1\u6709 Python \u7684 Windows \u73af\u5883\u4e0b\u8fd0\u884c\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aexe\u6587\u4ef6\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<p>1\u3001\u5728\u300c\u63d0\u793a\u97f3\u5de5\u5177\u300d\u6587\u4ef6\u5939\u7684\u5730\u5740\u680f\u4e2d\uff0c\u952e\u5165cmd\uff0c\u5e76\u56de\u8f66<\/p>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"244\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-43.png\" alt=\"\" class=\"wp-image-2928\"\/><\/figure>\n\n\n\n<p>2\u3001\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u4e2d\uff0c\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u56de\u8f66\uff1a<\/p>\n\n\n\t\t<div class='wp-block-bch-code-highlight  align' id='bhcCodeHighlight-befc58d3-d' data-attributes='{&quot;cId&quot;:&quot;befc58d3-d&quot;,&quot;code&quot;:&quot;pyinstaller -F \\u63d0\\u793a\\u97f3\\u5de5\\u5177.py\\n&quot;,&quot;theme&quot;:&quot;porple&quot;,&quot;align&quot;:&quot;&quot;,&quot;language&quot;:&quot;javascript&quot;,&quot;lineNumbers&quot;:true,&quot;codeTypo&quot;:{&quot;desktop&quot;:18,&quot;tablet&quot;:15,&quot;mobile&quot;:14},&quot;clipBoard&quot;:true,&quot;wordWrap&quot;:true,&quot;width&quot;:{&quot;desktop&quot;:&quot;100%&quot;,&quot;tablet&quot;:&quot;100%&quot;,&quot;mobile&quot;:&quot;100%&quot;},&quot;height&quot;:{&quot;desktop&quot;:&quot;0px&quot;,&quot;tablet&quot;:&quot;0px&quot;,&quot;mobile&quot;:&quot;0px&quot;},&quot;padding&quot;:{&quot;top&quot;:&quot;0px&quot;,&quot;right&quot;:&quot;0px&quot;,&quot;bottom&quot;:&quot;0px&quot;,&quot;left&quot;:&quot;0px&quot;},&quot;background&quot;:{&quot;color&quot;:&quot;#d3cfcf42&quot;},&quot;layout&quot;:{&quot;align&quot;:&quot;left&quot;},&quot;border&quot;:{&quot;color&quot;:&quot;#000&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;width&quot;:&quot;0px&quot;},&quot;shadow&quot;:[],&quot;alignment&quot;:&quot;center&quot;,&quot;clipBoardColors&quot;:{&quot;color&quot;:&quot;#fff&quot;,&quot;bg&quot;:&quot;#00000024&quot;}}'><\/div>\r\n\r\n\t\t\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"377\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-44.png\" alt=\"\" class=\"wp-image-2929\" srcset=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-44.png 872w, https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-44-768x332.png 768w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/figure>\n\n\n\n<p>3\u3001\u7ea6\u6570\u79d2\u540e\uff0c\u5373\u53ef\u5728 dist \u6587\u4ef6\u5939\u4e2d\u751f\u6210\u300c<code>\u63d0\u793a\u97f3\u5de5\u5177.exe<\/code>\u300d\uff0c\u6587\u4ef6\u5927\u5c0f\u7ea68MB\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6b64\u6587\u4ef6\u53ef\u4e0d\u4f9d\u8d56 Python \u73af\u5883\u8fd0\u884c\uff0c\u53ef\u62f7\u8d1d\u81f3\u5176\u4ed6 Windows \u4e2d\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>\u751f\u6210\u7684build\u6587\u4ef6\u5939<code>\uff08\u4e34\u65f6\u5efa\u6784\u76ee\u5f55\uff09<\/code>\u53ca.spec\u6587\u4ef6<code>\uff08\u914d\u7f6e\u6587\u4ef6\uff09<\/code>\u65e0\u9700\u4e00\u5e76\u62f7\u8d1d\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"160\" src=\"https:\/\/blog.kangyue.pro\/wp-content\/uploads\/2025\/06\/image-45.png\" alt=\"\" class=\"wp-image-2930\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h5 class=\"wp-block-heading\">\u2705 <code>build<\/code> \u6587\u4ef6\u5939<\/h5>\n\n\n\n<p>\u8fd9\u662f <strong>\u4e34\u65f6\u6784\u5efa\u76ee\u5f55<\/strong>\uff0c\u7528\u6765\u5b58\u653e\u4e2d\u95f4\u6587\u4ef6\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7f16\u8bd1\u8fc7\u7684 <code>.pyc<\/code> \u6587\u4ef6<\/li>\n\n\n\n<li>\u4f9d\u8d56\u7684\u8d44\u6e90\uff08DLL\u3001\u6a21\u5757\u7b49\uff09\u7684\u4e34\u65f6\u7f13\u5b58<\/li>\n\n\n\n<li>\u6253\u5305\u5206\u6790\u65e5\u5fd7<\/li>\n<\/ul>\n\n\n\n<p>\u5b83\u662f <strong>\u751f\u6210 <code>.exe<\/code> \u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u4e34\u65f6\u76ee\u5f55<\/strong>\uff0c\u6210\u529f\u6253\u5305\u540e\u53ef\u4ee5\u5220\u6389\uff0c\u4e0d\u5f71\u54cd <code>.exe<\/code> \u4f7f\u7528\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u2705 <code>.spec<\/code> \u6587\u4ef6<\/h5>\n\n\n\n<p>\u8fd9\u662f PyInstaller \u81ea\u52a8\u751f\u6210\u7684\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u9ed8\u8ba4\u4e0e\u4f60\u7684 <code>.py<\/code> \u6587\u4ef6\u540c\u540d\u3002<\/p>\n\n\n\n<p>\u5b83\u5305\u542b\u4e86 PyInstaller \u6253\u5305\u7684\u201c\u914d\u65b9\u201d\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8981\u6253\u5305\u7684\u4e3b\u811a\u672c\u8def\u5f84<\/li>\n\n\n\n<li>\u7a0b\u5e8f\u540d<\/li>\n\n\n\n<li>\u662f\u5426\u662f\u5355\u6587\u4ef6\uff08<code>--onefile<\/code>\uff09<\/li>\n\n\n\n<li>\u662f\u5426\u5305\u542b\u56fe\u6807<\/li>\n\n\n\n<li>\u4f9d\u8d56\u7684\u5176\u4ed6\u6587\u4ef6\uff08\u5982\u58f0\u97f3\u3001\u56fe\u7247\u3001\u5b57\u4f53\u7b49\uff09<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6210\u54c1\u5de5\u5177 V5.0 \u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684\u684c\u9762\u54cd\u94c3\u63d0\u793a\u5de5\u5177\uff0c\u9002\u7528\u4e8e Windows \u7cfb\u7edf\uff0c\u5e2e\u52a9\u4f60\u6309\u65f6\u63d0\u9192\u3001\u5b9a\u65f6\u4e13\u6ce8\u3001\u89c4\u5f8b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,5,6],"tags":[],"class_list":["post-2920","post","type-post","status-publish","format-standard","hentry","category-windows","category-5","category-6"],"_links":{"self":[{"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/posts\/2920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2920"}],"version-history":[{"count":10,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/posts\/2920\/revisions"}],"predecessor-version":[{"id":3620,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=\/wp\/v2\/posts\/2920\/revisions\/3620"}],"wp:attachment":[{"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kangyue.pro\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}