0

I have this code:

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()

This is my screenshot app made in python, using tkinter and pillow. I press a button, the tkinter window dissapears, takes a screenshot and appears back.

My screenshots are saved in order "Screenshot 1.png, Screenshot 2.png,etc." But if it take a screenshot or more and I open the app again to make a new one it overwrites them I tried to resolve it but I couldn't Any help?

0 Answers0