May 2019
Intermediate to advanced
542 pages
13h 37m
English
After creating a snazzy meme image, our user probably wants to save it so that they can upload it to their favorite social media website. To enable that, let's head back to MainWindow.__init_() and create a toolbar:
toolbar = self.addToolBar('File') toolbar.addAction("Save Image", self.save_image)
You could, of course, do this using the menu options or another widget. In any case, we need to define the save_image() method called by this action:
def save_image(self): save_file, _ = qtw.QFileDialog.getSaveFileName( None, "Save your image", qtc.QDir.homePath(), "PNG Images (*.png)") if save_file: self.image.save(save_file, "PNG")
To save a QImage file to disk, we need to call its save() method with a file path string and a ...
Read now
Unlock full access