1

Following the query here:

QGIS capture screenshot of visible map (PyQGIS or other alternatives)

I would like to have the Export PDF option confined to clicking the button on my keyboard.

By using the solutions available here:

https://datatofish.com/screenshot-python/

I tried to do something like this with my code:

 import keyboard

 # if keyboard.is_pressed('Alt+S'):  (optionally, although I can still use the Run function in my Python console)

 file_path = filedialog.asksaveasfilename(defaultextension='.png')
 iface.mapCanvas().saveAsImage(file_path)

But I am getting errors i.e.

Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.12\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 5 file_path = filedialog.asksaveasfilename(defaultextension='.png') ^

IndentationError: expected an indented block**

How can I save my screenshot with choosing and file name option?

I used another approach:

    iface.mapCanvas().saveAsImage(QFileDialog.getSaveFileName(mainWin, "Save 
    file", "", "PNG Format (*.png)"))

but I am getting an error here:

Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.12\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 1, in TypeError: QgsMapCanvas.saveAsImage(): argument 1 has unexpected type 'tuple'

1 Answer 1

0

If line 90 follows an if statement, it must be indented in Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.