def save_file(self):
        """
        Save active canvas to image file.
        :return:
        """
        path, _ = QFileDialog.getSaveFileName(
            self, "Save file", "", "PNG Image file (*.png)"
        )

        if path:
            pixmap = self.canvas.pixmap()
            pixmap.save(path, "PNG")

        Save active canvas to image file.
        :return:
        
pyqt5/demos/paint/main.py