pyautogui 没有将屏幕截图保存到我告诉它的目录
pyautogui not saving screenshot to the directory i told it to
我正在制作一个程序来帮助我在学校快速截取屏幕截图lectures.I 告诉 pyautogui 将屏幕截图保存到一个目录,但它没有将它保存在那里,而是将它保存在脚本所在的文件夹中 present.It 也没有给出任何 error.Just 没有将它保存到我想要的路径。
我的代码:-
import tkinter as tk
import pyautogui
import keyboard
from datetime import date
from tkinter import filedialog
r = tk.Tk()
r.geometry("600x300")
r.configure(background="white")
def startss():
while True:
if keyboard.is_pressed("insert"):
with open("chemistry.txt","r") as a:
b = a.read()
with open("chemistry.txt","w") as c:
newval = int(b) + 1
c.write(str(newval))
todaydate = date.today()
name = "Chemistry-" + str(b) + "-" + str(todaydate) + ".jpeg"
myScreenshot = pyautogui.screenshot(name)
myScreenshot.save(r"C:\Users\Hp\Desktop\Maheer\Study\Chemistry")
heading = tk.Label(r,text="Study-Screenshotter",fg="grey",bg="white",font="Arial 20 bold")
heading.place(relx=0.5,rely=0,anchor="n")
ctext = tk.Label(r,text="Chemistry=F1",fg="black",bg="white",font="Arial 15 bold")
ctext.place(relx=0.11,rely=0.25,anchor="n")
btext = tk.Label(r,text="Biology=F2",fg="black",bg="white",font="Arial 15 bold")
btext.place(relx=0.9,rely=0.25,anchor="n")
ptext = tk.Label(r,text="Physics=F3",fg="black",bg="white",font="Arial 15 bold")
ptext.place(relx=0.1,rely=0.45,anchor="n")
mtext = tk.Label(r,text="Maths=F4",fg="black",bg="white",font="Arial 15 bold")
mtext.place(relx=0.9,rely=0.45,anchor="n")
etext = tk.Label(r,text="English=F4",fg="black",bg="white",font="Arial 15 bold")
etext.place(relx=0.5,rely=0.65,anchor="n")
startbutton = tk.Button(r,text="Start",fg="black",bg="white",font="Arial 15 bold",command=startss)
startbutton.place(relx=0.5,rely=0.8,anchor="n")
r.mainloop()
Tkinter 回调异常
追溯(最近一次通话):
文件“C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py”,第 2138 行,保存
格式 = 扩展 [分机]
键错误:''
上述异常是以下异常的直接原因:
Traceback (most recent call last):
File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\Users\Hp\Desktop\Maheer\Study\Study-Screenshotter.py", line 25, in startss
myScreenshot.save(rpath)
File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py", line 2140, in save
raise ValueError("unknown file extension: {}".format(ext)) from e
ValueError: unknown file extension:
如果我尝试使用双正斜杠或其他模块(例如 os.path
,我会收到此错误
这是我在我的代码中使用的代码,运行良好:
pyautogui.screenshot(imageFilename=r"H:\some\location\image.PNG"),
region=(Coordinate_X, Coordinate_Y, 300, 50))
尝试使用 name-value 对,就像我使用 imageFilename=
一样。您不必截取屏幕截图并将其保存在另一行中。对于您的情况,请尝试:
image_loc = r'C:\Users\Hp\Desktop\Maheer\Study\Chemistry\' + name
pyautogui.screenshot(imageFilename=image_loc)
我正在制作一个程序来帮助我在学校快速截取屏幕截图lectures.I 告诉 pyautogui 将屏幕截图保存到一个目录,但它没有将它保存在那里,而是将它保存在脚本所在的文件夹中 present.It 也没有给出任何 error.Just 没有将它保存到我想要的路径。 我的代码:-
import tkinter as tk
import pyautogui
import keyboard
from datetime import date
from tkinter import filedialog
r = tk.Tk()
r.geometry("600x300")
r.configure(background="white")
def startss():
while True:
if keyboard.is_pressed("insert"):
with open("chemistry.txt","r") as a:
b = a.read()
with open("chemistry.txt","w") as c:
newval = int(b) + 1
c.write(str(newval))
todaydate = date.today()
name = "Chemistry-" + str(b) + "-" + str(todaydate) + ".jpeg"
myScreenshot = pyautogui.screenshot(name)
myScreenshot.save(r"C:\Users\Hp\Desktop\Maheer\Study\Chemistry")
heading = tk.Label(r,text="Study-Screenshotter",fg="grey",bg="white",font="Arial 20 bold")
heading.place(relx=0.5,rely=0,anchor="n")
ctext = tk.Label(r,text="Chemistry=F1",fg="black",bg="white",font="Arial 15 bold")
ctext.place(relx=0.11,rely=0.25,anchor="n")
btext = tk.Label(r,text="Biology=F2",fg="black",bg="white",font="Arial 15 bold")
btext.place(relx=0.9,rely=0.25,anchor="n")
ptext = tk.Label(r,text="Physics=F3",fg="black",bg="white",font="Arial 15 bold")
ptext.place(relx=0.1,rely=0.45,anchor="n")
mtext = tk.Label(r,text="Maths=F4",fg="black",bg="white",font="Arial 15 bold")
mtext.place(relx=0.9,rely=0.45,anchor="n")
etext = tk.Label(r,text="English=F4",fg="black",bg="white",font="Arial 15 bold")
etext.place(relx=0.5,rely=0.65,anchor="n")
startbutton = tk.Button(r,text="Start",fg="black",bg="white",font="Arial 15 bold",command=startss)
startbutton.place(relx=0.5,rely=0.8,anchor="n")
r.mainloop()
Tkinter 回调异常 追溯(最近一次通话): 文件“C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py”,第 2138 行,保存 格式 = 扩展 [分机] 键错误:''
上述异常是以下异常的直接原因:
Traceback (most recent call last):
File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\Users\Hp\Desktop\Maheer\Study\Study-Screenshotter.py", line 25, in startss
myScreenshot.save(rpath)
File "C:\Users\Hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py", line 2140, in save
raise ValueError("unknown file extension: {}".format(ext)) from e
ValueError: unknown file extension:
如果我尝试使用双正斜杠或其他模块(例如 os.path
,我会收到此错误这是我在我的代码中使用的代码,运行良好:
pyautogui.screenshot(imageFilename=r"H:\some\location\image.PNG"),
region=(Coordinate_X, Coordinate_Y, 300, 50))
尝试使用 name-value 对,就像我使用 imageFilename=
一样。您不必截取屏幕截图并将其保存在另一行中。对于您的情况,请尝试:
image_loc = r'C:\Users\Hp\Desktop\Maheer\Study\Chemistry\' + name
pyautogui.screenshot(imageFilename=image_loc)