Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python take a screenshot

import pyautogui

myScreenshot = pyautogui.screenshot()
myScreenshot.save(r'Path to save screenshotfile name.png')
Comment

How to take a screenshot using python

import pyautogui
screenshot = pyautogui.screenshot()
screenshot.save("FilePathwhereyouwantToSaveFileName.FileFormat")
Comment

python create and show screenshot

import numpy as np
import pyautogui
import scipy.ndimage
import pygame


class Viewer:
    def __init__(self, display_size):
        pygame.init()
        self.display = pygame.display.set_mode(display_size)
        self.pic = np.zeros((*display_size, 3), dtype=np.uint8)

    def set_title(self, title):
        pygame.display.set_caption(title)

    def set_image(self, image):
        self.pic = image

    def start(self):
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False

            surf = pygame.surfarray.make_surface(self.pic)
            self.display.blit(surf, (0, 0))

            pygame.display.update()

        pygame.quit()


viewer = Viewer((700, 700))

screen_size = pyautogui.size()

img = pyautogui.screenshot()
img = np.array(img)
img = np.rot90(img)
img = np.flipud(img)
background = np.zeros((700, 700, 3), dtype=np.uint8)
img = scipy.ndimage.zoom(img, (min(700 / img.shape[0], 700 / img.shape[1]),
                               min(700 / img.shape[0], 700 / img.shape[1]), 1))
# blend the image with the background
background[int(350 - img.shape[0] / 2):int(350 + img.shape[0] / 2),
           int(350 - img.shape[1] / 2):int(350 + img.shape[1] / 2), :] = img
viewer.set_image(background)
viewer.start()
Comment

fastest way to take screenshot python

import mss
import numpy as np

with mss.mss() as sct:
    monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
    img_array = np.array(sct.grab(monitor))
    # Do whatever you want...
Comment

how to take screenshot with python


import pyautogui
im2 = pyautogui.screenshot('my_screenshot.png', region=(x,y, width, height))
Comment

PREVIOUS NEXT
Code Example
Python :: convert image to binary python 
Python :: puython is not equal to 
Python :: dockerize django 
Python :: how to specify symbol in matplotlib 
Python :: Default stride value in keras 
Python :: python string replace by index 
Python :: pandas read csv with lists 
Python :: pandas df tail 
Python :: how to form .cleaned data in class based views in django 
Python :: using shebang python 
Python :: dynamic footer in django 
Python :: python local nosql database 
Python :: extract directory python 
Python :: numpy diag() 
Python :: python sort a list using defined order 
Python :: division of 2 numbers in python 
Python :: python numpy how to empty array cycle 
Python :: py quick sort 
Python :: python regex split 
Python :: print in python 
Python :: df loc 
Python :: take columns to rows in pandas 
Python :: += in python 
Python :: how to split a string by space in python 
Python :: stemming words python 
Python :: python code to convert csv to xml 
Python :: how to become python developer 
Python :: |safe django 
Python :: for loop in python 
Python :: stack python 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =