Skip to content Skip to sidebar Skip to footer

Python Auto Save Printscreen

Iv'e recently started learning python programming and ran into some problems with my first program. It's a program that auto-saves print screens. If i have a print screen saved in

Solution 1:

Two points:

  1. When using Tkinter it already has a mainloop (e.g. while True:). When you create your own main loop, you prevent Tkinter from doing the processing it should.

  2. If you want to actually register a hotkey, there are severalways to do it.

What you'll actually want to do is something more along the lines of this:

import Tkinter as tk
from PIL import Image, ImageGrab

root = tk.Tk()
last_image = Nonedefgrab_it():
    global last_image
    im = ImageGrab.grabclipboard()
    # Only want to save images if its a new image and is actually an image.# Not sure if you can compare Images this way, though - check the PIL docs.if im != last_image andisinstance(im, Image):
        last_image = im
        im.save('filename goes here')
    # This will inject your function call into Tkinter's mainloop.
    root.after(100, grab_it) 

grab_it() # Starts off the process

Solution 2:

you should use grab() if you want to take a image of the screen

from PIL importImageGrabim= ImageGrab.grab()
im.save("save.png")

Post a Comment for "Python Auto Save Printscreen"