{"id":3304,"date":"2023-09-07T10:53:31","date_gmt":"2023-09-07T02:53:31","guid":{"rendered":"https:\/\/benson80.eu.org\/?p=3304"},"modified":"2023-09-07T11:02:50","modified_gmt":"2023-09-07T03:02:50","slug":"%e5%b0%86python%e8%84%9a%e6%9c%ac%e7%bc%96%e8%af%91%e6%88%90%e5%8f%af%e6%89%a7%e8%a1%8c%e7%9a%84-exe%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=3304","title":{"rendered":"\u5c06Python\u811a\u672c\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u7684.exe\u6587\u4ef6"},"content":{"rendered":"\n<p>\u5b89\u88c5PyInstaller<br><strong>pip install pyinstaller<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528PyInstaller\u7f16\u8bd1Python\u811a\u672c\u4e3a.exe\u6587\u4ef6<br><strong>pyinstaller &#8211;onefile screenshot.py<\/strong><br>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2adist\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7f16\u8bd1\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\u6587\u4ef6\uff09\u3002<br>\u5728dist\u76ee\u5f55\u4e2d\u627e\u5230\u4f60\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5b83\u7684\u540d\u79f0\u5e94\u8be5\u4e0e\u4f60\u7684Python\u811a\u672c\u76f8\u540c\uff08\u5728\u672c\u4f8b\u4e2d\u662fscreenshot.exe\uff09\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5c06screenshot.exe\u6587\u4ef6\u62f7\u8d1d\u5230\u5176\u4ed6\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\uff0c\u800c\u65e0\u9700\u5b89\u88c5Python\u3002\u8bf7\u6ce8\u610f\uff0c\u751f\u6210\u7684.exe\u6587\u4ef6\u53ef\u80fd\u4f1a\u6bd4Python\u811a\u672c\u672c\u8eab\u5927\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86Python\u89e3\u91ca\u5668\u548c\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002<\/p>\n\n\n\n<p>\u9644\u4e0ascreenshot.py\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>import time<br>import pyautogui<br>from PIL import ImageGrab<\/p>\n\n\n\n<p># \u8bbe\u7f6e\u622a\u5c4f\u4fdd\u5b58\u7684\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u540d\u524d\u7f00<\/p>\n\n\n\n<p>save_folder = &#8220;E:\/\u622a\u56fe\/&#8221;<br>file_prefix = &#8220;test&#8221;<\/p>\n\n\n\n<p># \u8bbe\u7f6e\u622a\u5c4f\u7684\u65f6\u95f4\u95f4\u9694\uff08\u79d2\uff09<\/p>\n\n\n\n<p>interval = 5 # \u4f8b\u5982\uff0c\u6bcf5\u79d2\u622a\u4e00\u6b21\u5c4f<\/p>\n\n\n\n<p>while True:<br># \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\u4f5c\u4e3a\u6587\u4ef6\u540d\u540e\u7f00\uff0c\u4ee5\u907f\u514d\u6587\u4ef6\u540d\u51b2\u7a81<br>timestamp = int(time.time())<br>file_name = f&#8221;{file_prefix}_{timestamp}.png&#8221;<br>file_path = save_folder + file_name<\/p>\n\n\n\n<p># \u622a\u5c4f\u5e76\u4fdd\u5b58<br>screenshot = ImageGrab.grab()<br>screenshot.save(file_path)<br><br># \u8f93\u51fa\u622a\u5c4f\u4fe1\u606f<br>print(f&#8221;\u622a\u5c4f\u5df2\u4fdd\u5b58\u81f3 {file_path}&#8221;)<br><br># \u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u540e\u518d\u6b21\u622a\u5c4f<br>time.sleep(interval)<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5PyInstallerpip install  &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-3304","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3304"}],"version-history":[{"count":6,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3304\/revisions"}],"predecessor-version":[{"id":3311,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/3304\/revisions\/3311"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}