I have a toolbar. It allows you to take screenshots with one button:
def screenshot():
try:
os.mkdir(r"C:\Screenshots")
except FileExistsError:
pass
global img
img = ImageGrab.grab()
global today
today = time.strftime("%d_%B_%Y__%H_%m_%S")
saveas=os.path.join(SaveDirectory, "Screenshot_" + today + ".jpg")
img.save(saveas)
bubble = Thread(target = balloon_tip, args = ("Saved!", "Screenshot was saved at C:\Screenshots"))
bubble.start()
However I get this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python3.6\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Python3.6\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\mbilal25tr\Desktop\Python Projects\Toolbar py\toolbar.pyw", line 140, in screenshot
img.save(saveas)
File "C:\Python3.6\lib\site-packages\PIL\Image.py", line 1725, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Screenshot\\Screenshot_29_March_2017__19_03_01.jpg'
But I don't get it! Isn't img.save()
supposed to create an image file? Why does it try to open it before creating? How should I expect it to find it and run without an error?
I'm using Python 3.
C:\Screeshots
but in error it isC:\Screenshot
. ans
is missing but why? I don't know any escaping ass\
! – Negligentlineoftext.strip()
instead, which removes newlines (and other whitespace) only if it's there. – Eparch