我希望我的python屏幕截图应用程序不覆盖屏幕截图

时间:2018-07-23 17:51:32

标签: python tkinter screenshot pillow

我有此代码:

import tkinter
from tkinter import *
from PIL import ImageGrab
from pynput.mouse import Controller, Button, Listener
import pynput
from pynput import keyboard
import time
import os.path

root = Tk()
root.title("PyScreenshot")
root.geometry("124x79")

current = set()

global save_path
save_path = "C:\\Users\\Bogdan\\Desktop\\Screenshots\\Screenshot 1.png"

global nr
nr = 0

def ss():
    global nr
    nr += 1
    global save_path
    save_path = "C:\\Users\\Bogdan\\Desktop\\Screenshots\\Screenshot " + str(nr) + ".png"
    root.withdraw()
    time.sleep(1)
    snapshot = ImageGrab.grab()
    box = (0, 91, 1679, 1011)
    snapshot.crop(box)
    snp = snapshot.crop(box)
    snp.save(save_path)
    root.deiconify()

def survivss():
    global nr
    nr += 1
    save_path = "C:\\Users\\Bogdan\\Desktop\\Screenshots\\Surviv Screenshot " + str(nr) + ".png"
    root.withdraw()
    time.sleep(1)
    snapshot = ImageGrab.grab()
    box = (300, 255, 1407, 856)
    snapshot.crop(box)
    snp = snapshot.crop(box)
    snp.save(save_path)
    root.deiconify()

def fullss():
    global nr
    nr += 1
    save_path = "C:\\Users\\Bogdan\\Desktop\\Screenshots\\Screenshot " + str(nr) + ".png"
    root.withdraw()
    time.sleep(1)
    snapshot = ImageGrab.grab()
    snapshot.save(save_path)
    root.deiconify()

b1 = tkinter.Button(root, text = "Screenshot", command = ss)
b1.grid(column = 0, row = 0)

b2 = tkinter.Button(root, text = "Surviv Screenshot", command = survivss)
b2.grid(column = 0, row = 1)

b2 = tkinter.Button(root, text = "Fullscreen Screenshot", command = fullss)
b2.grid(column = 0, row = 2)

root.mainloop()

这是我使用tkinter和枕头用python制作的屏幕截图应用。 我按下一个按钮,tkinter窗口消失,截图,然后又出现。

我的屏幕截图按“屏幕截图1.png,屏幕截图2.png等”的顺序保存。 但是,如果需要截图或更多截图,然后我再次打开该应用以制作一个新的应用,它将覆盖它们 我试图解决它,但是我做不到 有帮助吗?

0 个答案:

没有答案