I am trying to create a py-code to initiate a user-defined screenshot on multiple monitors (win+shift+S) and save the screenshot as image. this is because the windows does not save image in “pictures/screenshots” when one use user-defined screenshot (win+shift+S).
I have tried to get help from ChatGPT, but it does not work well will multiple monitors.
Has somebody here idea how to fix this?
here is some draft, but i does not work as it suppose to:
`
import pyscreenshot as ImageGrab
from tkinter import Tk, Canvas, BooleanVar
import datetime
def take_screenshot():
# Hide the main window
root.withdraw()
# Wait for the user to select an area
root.update()
# Get the user's selection
x0 = root.winfo_pointerx()
y0 = root.winfo_pointery()
# Wait for the user to release the mouse button
root.wait_variable(mouse_released)
x1 = root.winfo_pointerx()
y1 = root.winfo_pointery()
# Show the main window again
root.deiconify()
# Capture the selected area
im = ImageGrab.grab(bbox=(x0, y0, x1, y1))
date_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
# Save the screenshot
save_path = fr'C:UsersxxxxxxPicturesScreenshotsscreenshot_{date_time}.png'
im.save(save_path)
print(f'Screenshot saved to {save_path}')
# Close the application
root.quit()
def on_mouse_release(event):
# Update the mouse_released variable to indicate that the mouse button has been released
mouse_released.set(True)
# Create the main window
root = Tk()
root.title('Screenshot Tool')
# Create a canvas to capture the mouse events
canvas = Canvas(root, width=300, height=200)
canvas.pack()
# Variable to indicate whether the mouse button has been released
mouse_released = BooleanVar(value=False)
# Bind the mouse release event
root.bind('<ButtonRelease-1>', on_mouse_release)
# Start the application
take_screenshot()
root.mainloop()
`
see above.
the code does not give the opportunity to take screenshot on all monitors (just main).
annapet mikel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.