截图文件夹和脚本
This commit is contained in:
80
截屏幕文件.py
Normal file
80
截屏幕文件.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import tkinter as tk
|
||||
from tkinter import simpledialog
|
||||
import pyautogui
|
||||
import keyboard
|
||||
import os
|
||||
|
||||
# 全局变量,用于存储文件夹路径
|
||||
save_folder = ""
|
||||
|
||||
|
||||
# 创建状态显示窗口
|
||||
def create_status_window():
|
||||
window = tk.Tk()
|
||||
window.title("截图工具状态")
|
||||
window.geometry("200x100")
|
||||
window_position = f"+{window.winfo_screenwidth() - 220}+{window.winfo_screenheight() - 150}"
|
||||
window.geometry(window_position)
|
||||
# 设置窗口始终在最前面
|
||||
window.attributes('-topmost', True)
|
||||
|
||||
label = tk.Label(window, text="", font=("Arial", 12))
|
||||
label.pack(expand=True)
|
||||
|
||||
return window, label
|
||||
|
||||
|
||||
# 更新状态信息
|
||||
def update_status(label, text):
|
||||
label.config(text=text)
|
||||
label.update()
|
||||
|
||||
|
||||
# 创建文件夹
|
||||
def create_folder():
|
||||
global save_folder
|
||||
root = tk.Tk()
|
||||
root.withdraw() # 隐藏主窗口
|
||||
folder_name = simpledialog.askstring("输入", "请输入文件夹名称:", parent=root)
|
||||
if folder_name:
|
||||
save_folder = os.path.join(os.getcwd(), folder_name)
|
||||
if not os.path.exists(save_folder):
|
||||
os.makedirs(save_folder)
|
||||
update_status(status_label, "文件夹创建成功")
|
||||
else:
|
||||
update_status(status_label, "文件夹已存在")
|
||||
root.destroy()
|
||||
|
||||
|
||||
# 截屏并保存
|
||||
def take_screenshot():
|
||||
if not save_folder:
|
||||
update_status(status_label, "请先创建文件夹")
|
||||
return
|
||||
|
||||
screen_width, screen_height = pyautogui.size()
|
||||
left = screen_width // 2 - 400
|
||||
top = 0
|
||||
right = screen_width // 2 + 400
|
||||
bottom = screen_height
|
||||
|
||||
screenshot = pyautogui.screenshot(region=(left, top, right - left, bottom - top))
|
||||
file_path = os.path.join(save_folder, f"screenshot_{len(os.listdir(save_folder)) + 1}.png")
|
||||
screenshot.save(file_path)
|
||||
update_status(status_label, "截图成功")
|
||||
|
||||
|
||||
# 主函数
|
||||
def main():
|
||||
global status_window, status_label
|
||||
status_window, status_label = create_status_window()
|
||||
|
||||
keyboard.add_hotkey('F8', create_folder)
|
||||
keyboard.add_hotkey('F9', take_screenshot)
|
||||
|
||||
update_status(status_label, " ready")
|
||||
status_window.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user