def screenshot(self, *args):
        """Take a screenshot, crop and save"""
        from mss import mss
        if not os.path.exists("screenshots"):
            os.makedirs("screenshots")
        box = {
            "top": self.winfo_y(),
            "left": self.winfo_x(),
            "width": self.winfo_width(),
            "height": self.winfo_height()
        }
        screenshot = mss().grab(box)
        screenshot = Image.frombytes("RGB", screenshot.size, screenshot.rgb)
        screenshot.save("screenshots/{}.png".format(ttk.Style(self).theme_use()))
def screenshot ( self , * args ) : from mss import mss if not os . path . exists ( "screenshots" ) : os . makedirs ( "screenshots" ) box = { "top" : self . winfo_y ( ) , "left" : self . winfo_x ( ) , "width" : self . winfo_width ( ) , "height" : self . winfo_height ( ) } screenshot = mss ( ) . grab ( box ) screenshot = Image . frombytes ( "RGB" , screenshot . size , screenshot . rgb ) screenshot . save ( "screenshots/{}.png" . format ( ttk . Style ( self ) . theme_use ( ) ) )
Take a screenshot, crop and save