from PIL import ImageGrab def save_clipboard_image(filename="screenshot.png"): # 1. 從剪貼簿抓取影像資料 img = ImageGrab.grabclipboard() # 2. 判斷剪貼簿裡是不是影像 if img is None: print("剪貼簿裡沒有影像喔!請先截圖再執行。") else: # 3. 儲存檔案 img.save(filename, "PNG") print(f"成功!影像已儲存為:{filename}") if __name__ == "__main__": save_clipboard_image()