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 clipboard and start the program it outputs a .png file. if i start the program with nothing in clipboard and then press print screen it outputs a .png file.
But if i press print screen after the program has already printed a .png file it does absolutely nothing. Can't even use ctrl+c to copy text.
This is the code im using.
from PIL import ImageGrab
from Tkinter import Tk
import time
r = Tk()
while True:
try:
im = ImageGrab.grabclipboard()
date = time.strftime("%Y-%m-%d %H.%M.%S")
im.save(date + ".png")
r.clipboard_clear()
except IOError:
pass
except AttributeError:
pass
you should use grab() if you want to take a image of the screen
Two points:
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.If you want to actually register a hotkey, there are several ways to do it.
What you'll actually want to do is something more along the lines of this: