{"id":143,"date":"2025-10-30T16:41:07","date_gmt":"2025-10-30T08:41:07","guid":{"rendered":"https:\/\/www.thebugmuxi.xyz\/?p=143"},"modified":"2025-10-30T16:41:08","modified_gmt":"2025-10-30T08:41:08","slug":"python%e5%bc%b9%e7%aa%97","status":"publish","type":"post","link":"https:\/\/www.thebugmuxi.xyz\/index.php\/2025\/10\/30\/python%e5%bc%b9%e7%aa%97\/","title":{"rendered":"python\u5f39\u7a97"},"content":{"rendered":"\n<p>\u6e90\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nimport tkinter as tk\nfrom tkinter import Toplevel, Label, Button\n\n\ndef show_warm_tip(tip: str) -> None:\n    window = Toplevel()\n    window.title(\"\u6e29\u99a8\u63d0\u793a\")\n\n    bg_colors: list&#91;str] = &#91;\n        \"lightpink\", \"skyblue\", \"lightgreen\", \"lavender\",\n        \"lightyellow\", \"plum\", \"coral\", \"bisque\", \"aquamarine\",\n        \"mistyrose\", \"honeydew\", \"lavenderblush\", \"oldlace\"\n    ]\n    bg: str = random.choice(bg_colors)\n\n    Label(\n        window,\n        text=tip,\n        bg=bg,\n        font=(\"\u5fae\u8f6f\u96c5\u9ed1\", 16),\n        width=30,\n        height=3\n    ).pack(pady=10)\n\n    Button(\n        window,\n        text=\"\u597d\u7684\",\n        command=window.destroy,\n        font=(\"\u5fae\u8f6f\u96c5\u9ed1\", 12)\n    ).pack(pady=5)\n\n      \n\n    x: int = random.randint(25, 2000)\n    y: int = random.randint(25, 1000)\n    window.geometry(f\"+{x}+{y}\")\n\n\ndef schedule_popups(tips: list&#91;str], interval: int = 100, count: int = 10) -> None:\n    if count > 0:\n        tip_text: str = random.choice(tips)\n        show_warm_tip(tip_text)\n        _ = root.after(interval, schedule_popups, tips, interval, count - 1)  # type: ignore\n\n\ndef main() -> None:\n    global root\n    root = tk.Tk()\n    root.withdraw()\n\n    tips: list&#91;str] = &#91;\n        \"\u8bf7\u6ce8\u610f\u4f11\u606f\uff01\",\n        \"\u591a\u559d\u6c34\u54e6\uff5e\",\n        \"\u8bb0\u5f97\u6d3b\u52a8\u4e00\u4e0b\uff01\",\n        \"\u4fdd\u62a4\u773c\u775b\u5f88\u91cd\u8981\uff01\",\n        \"\u5de5\u4f5c\u8f9b\u82e6\u4e86\uff01\",\n        \"\u4fdd\u6301\u597d\u5fc3\u60c5\uff01\",\n        \"\u6ce8\u610f\u5750\u59ff\uff01\",\n        \"\u8bb0\u5f97\u4fdd\u5b58\u5de5\u4f5c\uff01\"\n    ]\n\n    schedule_popups(tips, interval=50, count=100)\n    root.mainloop()\n\n\nif __name__ == \"__main__\":\n    main()<\/code><\/pre>\n\n\n\n<p>\u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0b\u8f7d\u8fde\u63a5<a href=\"https:\/\/www.123865.com\/s\/dy0yVv-8ijwd\" data-type=\"link\" data-id=\"https:\/\/www.123865.com\/s\/dy0yVv-8ijwd\">https:\/\/www.123865.com\/s\/dy0yVv-8ijwd<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6e90\u7801 \u6253\u5305\u597d\u7684\u6587\u4ef6\u4e0b\u8f7d\u8fde\u63a5https:\/\/www.123865.com\/s\/dy0yVv-8ijwd<\/p>\n","protected":false},"author":1,"featured_media":23,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-143","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=143"}],"version-history":[{"count":1,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"predecessor-version":[{"id":144,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/143\/revisions\/144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/media\/23"}],"wp:attachment":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}