{"id":72,"date":"2025-11-05T16:52:28","date_gmt":"2025-11-05T08:52:28","guid":{"rendered":"https:\/\/blog.genan.top\/?p=72"},"modified":"2025-11-05T23:40:57","modified_gmt":"2025-11-05T15:40:57","slug":"python%e7%aa%97%e5%8f%a3%e7%bc%96%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/blog.genan.top\/?p=72","title":{"rendered":"Python\u5fc3\u5f62\u5f39\u7a97"},"content":{"rendered":"\n<p>\u5206\u4eab\u4e00\u4e2a\u7531python\u5199\u7684\u521b\u610f\u5fc3\u5f62\u5f39\u7a97:<br>\u6548\u679c\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97.png\"><img loading=\"lazy\" decoding=\"async\"  src=\"https:\/\/blog.genan.top\/wp-content\/themes\/lolimeow-master\/assets\/images\/loading.gif\" data-src=\"https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97-1024x555.png\" class=\"lazy\" loading=\"lazy\" alt=\"\" class=\"wp-image-75\" srcset=\"https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97-1024x555.png 1024w, https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97-300x163.png 300w, https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97-768x416.png 768w, https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97-1536x832.png 1536w, https:\/\/blog.genan.top\/wp-content\/uploads\/2025\/11\/\u5fc3\u5f62\u5f39\u7a97.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p>\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tkinter as tk\nimport random\nimport math\n\ntips = &#91;\n    \"\u5929\u51b7\u591a\u7a7f\u8863\u670d\", \"\u591a\u559d\u70ed\u6c34\", \"\u8981\u5403\u70ed\u996d\", \"\u6211\u60f3\u4f60\u4e86\",\n    \"\u4fdd\u6301\u5fae\u7b11~~~(^v^)~~~\", \"\u4fdd\u6301\u597d\u5fc3\u60c5\u5440\", \"\u597d\u597d\u7231\u81ea\u5df1\", \"\u68a6\u60f3\u6210\u771f\",\n    \"\u522b\u71ac\u591c\", \"\u6240\u6709\u7684\u70e6\u607c\u90fd\u6d88\u5931\", \"\u8eab\u4f53\u500d\u513f\u68d2\", \"\u5403\u561b\u561b\u9999\",\n    \"\u6bcf\u5929\u90fd\u8981\u5143\u6c14\u6ee1\u6ee1\", \"\u5347\u804c\u52a0\u85aa!\", \"\u671f\u5f85\u4e0b\u6b21\u89c1\u9762\"\n]\n\ncolors = &#91;\n    'lightpink', 'skyblue', 'lightgreen', 'lavender',\n    'lightyellow', 'plum', 'coral', 'bisque', 'aquamarine',\n    'mistyrose', 'honeydew', 'lavenderblush', 'oldlace'\n]\n\n\ndef get_screen_resolution():\n    \"\"\"\u83b7\u53d6\u5c4f\u5e55\u5206\u8fa8\u7387\"\"\"\n    root = tk.Tk()\n    root.withdraw()\n    screen_width = root.winfo_screenwidth()\n    screen_height = root.winfo_screenheight()\n    root.destroy()\n    return screen_width, screen_height\n\n\ndef heart_coordinates(num_points):\n    \"\"\"\u6807\u51c6\u5fc3\u5f62\u5750\u6807\"\"\"\n    points = &#91;]\n    for i in range(num_points):\n        t = 2 * math.pi * i \/ num_points\n        x = 16 * (math.sin(t) ** 3)\n        y = 13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)\n        points.append((x, y))\n    return points\n\n\ndef create_heart_window(x, y, root, screen_width, screen_height):\n    \"\"\"\u521b\u5efa\u5355\u4e2a\u5fc3\u5f62\u7a97\u53e3\"\"\"\n    # \u5750\u6807\u8f6c\u6362\n    scale_factor = min(screen_width, screen_height) \/ 1500\n    screen_x = int(x * 30 * scale_factor + screen_width \/ 2)\n    screen_y = int(-y * 30 * scale_factor + screen_height \/ 2)\n\n    # \u521b\u5efa\u7a97\u53e3\n    window = tk.Toplevel()\n    window.title(\"\u4f60\u597d\u5440~\")\n    window.geometry(f\"250x100+{screen_x}+{screen_y}\")\n\n    # \u968f\u673a\u9009\u62e9\u989c\u8272\u548c\u6587\u5b57\n    color = random.choice(colors)\n    text = random.choice(tips)\n\n    # \u8bbe\u7f6e\u7a97\u53e3\u6837\u5f0f\n    window.configure(background=color)\n    label = tk.Label(\n        window,\n        text=text,\n        bg=color,\n        font=(\"\u5fae\u8f6f\u96c5\u9ed1\", 16, \"bold\")\n    )\n    label.pack()\n\n    # \u7ed1\u5b9a\u5173\u95ed\u4e8b\u4ef6\n    def on_closing():\n        root.destroy()\n    window.protocol(\"WM_DELETE_WINDOW\", on_closing)\n\n\ndef create_heart_sequence():\n    \"\"\"\u521b\u5efa\u5fc3\u5f62\u5e8f\u5217\u7a97\u53e3\"\"\"\n    # \u83b7\u53d6\u5c4f\u5e55\u4fe1\u606f\n    screen_width, screen_height = get_screen_resolution()\n    print(f\"\u5c4f\u5e55\u5206\u8fa8\u7387: {screen_width}x{screen_height}\")\n\n    # \u8ba1\u7b97\u5fc3\u5f62\u5750\u6807\n    points = heart_coordinates(60)\n\n    # \u521b\u5efa\u9690\u85cf\u7684\u4e3b\u63a7\u5236\u7a97\u53e3\n    root = tk.Tk()\n    root.withdraw()\n\n    current_index = 0\n\n    def create_next_window():\n        nonlocal current_index\n        if current_index &lt; len(points):\n            x, y = points&#91;current_index]\n            create_heart_window(x, y, root, screen_width, screen_height)\n            current_index += 1\n            root.after(350, create_next_window)  # 350ms\u540e\u521b\u5efa\u4e0b\u4e00\u4e2a\n\n    # \u7acb\u5373\u5f00\u59cb\u751f\u6210\n    root.after(100, create_next_window)\n    root.mainloop()\n\n\n# \u8fd0\u884c\u5fc3\u5f62\u5e8f\u5217\ncreate_heart_sequence()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u4eab\u4e00\u4e2a\u7531python\u5199\u7684\u521b\u610f\u5fc3\u5f62\u5f39\u7a97:\u6548\u679c\u56fe\u5982\u4e0b\uff1a \u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.genan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":6,"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/blog.genan.top\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/blog.genan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.genan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.genan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}