目录
点击一下按钮,截个屏
import os
import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QVBoxLayout
from PyQt5.QtGui import QScreen
from PyQt5.QtCore import QDateTime, Qt
import datetime
def capture_screen():
# 获取当前应用程序和屏幕
app = QApplication.instance()
screen = app.primaryScreen()
# 获取当前时间作为文件名
now = datetime.datetime.now()
filename = now.strftime('%Y%m%d_%H%M%S.jpg')
# 获取截图并保存
screenshot = screen.grabWindow(0)
screenshot.save(save_dir+filename, 'jpg')
print(f"Screenshot saved as {filename}")
class MainWin