{"id":45,"date":"2025-11-02T11:08:19","date_gmt":"2025-11-02T03:08:19","guid":{"rendered":"https:\/\/www.linerroom.cn\/?p=45"},"modified":"2025-11-02T11:09:17","modified_gmt":"2025-11-02T03:09:17","slug":"%e5%bc%b9%e7%aa%97%ef%bc%88python%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.linerroom.cn\/?p=45","title":{"rendered":"\u5f39\u7a97\u6587\u6848\uff08python\uff09"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.linerroom.cn\/wp-content\/uploads\/2025\/11\/image-1024x640.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"640\" data-attachment-id=\"46\" data-permalink=\"https:\/\/www.linerroom.cn\/?attachment_id=46\" data-orig-file=\"https:\/\/i0.wp.com\/www.linerroom.cn\/wp-content\/uploads\/2025\/11\/image.png?fit=2560%2C1600&amp;ssl=1\" data-orig-size=\"2560,1600\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.linerroom.cn\/wp-content\/uploads\/2025\/11\/image.png?fit=300%2C188&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.linerroom.cn\/wp-content\/uploads\/2025\/11\/image.png?fit=1024%2C640&amp;ssl=1\" data-original=\"https:\/\/www.linerroom.cn\/wp-content\/uploads\/2025\/11\/image-1024x640.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-46\"  sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import tkinter as tk\nimport random\n\n# \u5f39\u7a97\u8ba1\u6570\u5668\uff08\u521d\u59cb\u4e3a0\uff09\nwindow_count = 0\n# \u6700\u5927\u5f39\u7a97\u6570\u91cf\nMAX_WINDOWS = 300\n\ndef create_warm_tip():\n    global window_count  # \u58f0\u660e\u4f7f\u7528\u5168\u5c40\u8ba1\u6570\u5668\n    # \u521b\u5efa\u5f39\u7a97\uff08\u5173\u8054\u4e3b\u7a97\u53e3 root\uff09\n    window = tk.Toplevel(root)\n\n    # \u83b7\u53d6\u5c4f\u5e55\u5bbd\u9ad8\n    screen_width = root.winfo_screenwidth()\n    screen_height = root.winfo_screenheight()\n\n    # \u968f\u673a\u7a97\u53e3\u4f4d\u7f6e\uff08\u786e\u4fdd\u5b8c\u5168\u663e\u793a\uff09\n    window_width = 250\n    window_height = 60\n    x = random.randrange(0, screen_width - window_width)\n    y = random.randrange(0, screen_height - window_height)\n\n    # \u8bbe\u7f6e\u7a97\u53e3\u6807\u9898\u3001\u5927\u5c0f\u548c\u4f4d\u7f6e\n    window.title('\u6e29\u99a8\u63d0\u793a')\n    window.geometry(f\"{window_width}x{window_height}+{x}+{y}\")\n\n    # \u968f\u673a\u63d0\u793a\u6587\u5b57\n    tips = &#91;\n        '\u591a\u559d\u6c34\u54e6~', '\u4fdd\u6301\u5fae\u7b11\u5440', '\u6bcf\u5929\u90fd\u8981\u5143\u6c14\u6ee1\u6ee1',\n        '\u8bb0\u5f97\u5403\u6c34\u679c', '\u4fdd\u6301\u597d\u5fc3\u60c5', '\u597d\u597d\u7231\u81ea\u5df1', '\u6211\u60f3\u4f60\u4e86',\n        '\u68a6\u60f3\u6210\u771f', '\u671f\u5f85\u4e0b\u4e00\u6b21\u89c1\u9762', '\u91d1\u699c\u9898\u540d',\n        '\u987a\u987a\u5229\u5229', '\u65e9\u70b9\u4f11\u606f', '\u613f\u6240\u6709\u70e6\u607c\u90fd\u6d88\u5931',\n        '\u522b\u71ac\u591c', '\u4eca\u5929\u8fc7\u5f97\u5f00\u5fc3\u561b', '\u5929\u51b7\u4e86\uff0c\u591a\u7a7f\u8863\u670d'\n    ]\n    tip = random.choice(tips)\n\n    # \u968f\u673a\u80cc\u666f\u989c\u8272\n    bg_colors = &#91;\n        'lightpink', 'skyblue', 'lightgreen', 'lavender',\n        'lightyellow', 'plum', 'coral', 'bisque', 'aquamarine',\n        'mistyrose', 'honeydew', 'lavenderblush', 'oldlace'\n    ]\n    bg = random.choice(bg_colors)\n\n    # \u521b\u5efa\u6807\u7b7e\u663e\u793a\u6587\u5b57\n    tk.Label(\n        window,\n        text=tip,\n        bg=bg,\n        font=('\u5fae\u8f6f\u96c5\u9ed1', 16),\n        width=30,\n        height=3\n    ).pack()\n\n    # \u7a97\u53e3\u7f6e\u9876\uff08\u65b0\u5f39\u7a97\u4f1a\u663e\u793a\u5728\u6700\u4e0a\u5c42\uff09\n    window.attributes('-topmost', True)\n\n    # \u5f39\u7a97\u6570\u91cf+1\n    window_count += 1\n\n\ndef auto_pop_tips(interval=10):  # \u95f4\u9694\u65f6\u95f4\uff08\u6beb\u79d2\uff09\uff0c0.3\u79d2=300\u6beb\u79d2\n    # \u53ea\u6709\u5f53\u5f39\u7a97\u6570\u91cf\u5c0f\u4e8e300\u65f6\uff0c\u624d\u7ee7\u7eed\u521b\u5efa\n    if window_count &lt; MAX_WINDOWS:\n        create_warm_tip()  # \u521b\u5efa\u4e00\u4e2a\u5f39\u7a97\n        # \u7ee7\u7eed\u5b9a\u65f6\u9012\u5f52\u8c03\u7528\uff08\u5b9e\u73b0\u5faa\u73af\u5f39\u7a97\uff09\n        root.after(interval, auto_pop_tips, interval)\n    else:\n        # \u8fbe\u5230300\u4e2a\u5f39\u7a97\u540e\uff0c\u6253\u5370\u63d0\u793a\u5e76\u505c\u6b62\n        print(f\"\u5df2\u8fbe\u5230\u6700\u5927\u5f39\u7a97\u6570\u91cf\uff08{MAX_WINDOWS}\u4e2a\uff09\uff0c\u81ea\u52a8\u6682\u505c\")\n\n\n# \u521b\u5efa\u4e3b\u7a97\u53e3\uff08\u9690\u85cf\uff0c\u4f5c\u4e3a\u6240\u6709\u5f39\u7a97\u7684\u7236\u7a97\u53e3\uff09\nroot = tk.Tk()\nroot.withdraw()  # \u9690\u85cf\u4e3b\u7a97\u53e3\n\n# \u542f\u52a8\u5b9a\u65f6\u5f39\u7a97\uff08\u95f4\u96940.3\u79d2\uff09\nauto_pop_tips(3000)\n\n# \u542f\u52a8\u4e3b\u5faa\u73af\nroot.mainloop()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bf4\u660e\uff1a<\/h2>\n\n\n\n<p>\u4f7f\u7528\u5e93\uff1atkinter    random<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u660e\uff1a \u4f7f\u7528\u5e93\uff1atkinter random<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-python"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":2,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linerroom.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}