MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / save_win

Function save_win

DemoPrograms/Demo_Save_Windows_As_Images.py:81–100  ·  view source on GitHub ↗

Saves a window with the title provided as a file using the provided filename. If one of them is missing, then a window is created and the information collected :param filename: :param title: :return:

(filename=None, title=None, crop=True)

Source from the content-addressed store, hash-verified

79 return titles
80
81def save_win(filename=None, title=None, crop=True):
82 """
83 Saves a window with the title provided as a file using the provided filename.
84 If one of them is missing, then a window is created and the information collected
85
86 :param filename:
87 :param title:
88 :return:
89 """
90 C = 7 if crop else 0 # pixels to crop
91 try:
92 fceuxHWND = win32gui.FindWindow(None, title)
93 rect = win32gui.GetWindowRect(fceuxHWND)
94 rect_cropped = (rect[0] + C, rect[1], rect[2] - C, rect[3] - C)
95 grab = ImageGrab.grab(bbox=rect_cropped)
96 grab.save(filename)
97 sg.cprint('Wrote image to file:')
98 sg.cprint(filename, c='white on purple')
99 except Exception as e:
100 sg.popup('Error trying to save screenshot file', e, keep_on_top=True)
101
102
103def main():

Callers 1

mainFunction · 0.70

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected