你可以使用以下代码来实现窗口被点击关闭时弹出“你关不掉我吧”的小窗口:\n\npython\nimport tkinter as tk\nimport random\nimport threading\nimport time\nimport winsound\nimport ctypes\nfrom tkinter import messagebox\n\ndef boom():\n def close_window():\n messagebox.showinfo("你关不掉我吧", "你关不掉我吧")\n\n window = tk.Tk()\n window.attributes("-topmost", True) # 设置窗口属性,使其置顶\n width = window.winfo_screenwidth()\n height = window.winfo_screenheight()\n a = random.randrange(0, width)\n b = random.randrange(0, height)\n window.title('迷你世界')\n window.geometry("700x600" + "+" + str(a) + "+" + str(b))\n window.protocol("WM_DELETE_WINDOW", close_window)\n tk.Label(window, text='还敢玩迷你世界不?', bg='red',\n font=('宋体', 30), width=100, height=1000).pack()\n ctypes.windll.user32.MessageBeep(0xFFFFFFFF)\n window.mainloop()\n\nthreads = []\nfor i in range(1000000):\n t = threading.Thread(target=boom)\n threads.append(t)\n time.sleep(0.00001)\n threads[i].start()\n\n\n在这个代码中,我们添加了一个新的函数close_window来弹出消息框。然后,我们在创建窗口时使用window.protocol("WM_DELETE_WINDOW", close_window)来指定窗口关闭时要执行的函数。这样,当窗口被点击关闭时,就会弹出消息框显示“你关不掉我吧”。

Python 代码实现窗口点击关闭弹出

原文地址: https://www.cveoy.top/t/topic/p3Kr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录