Python screenshot

941 views
Skip to first unread message

Arjun Thekkummadathil

unread,
Oct 6, 2016, 5:00:54 AM10/6/16
to python_in...@googlegroups.com
Hi
   Anyone knows any existing library or quick method to do a screenshot using python. I should be able to select a region to be screen grabbed. Am looking for an option on windows.

thanks

Arjun

Marcus Ottosson

unread,
Oct 6, 2016, 5:09:16 AM10/6/16
to python_in...@googlegroups.com

There’s always trusty old Qt.

# From within Maya
import os
from PySide.QtGui import QPixmap, QApplication

app = QApplication.instance()
screenshot = QPixmap.grabWindow(app.desktop().winId())
screenshot.save(os.path.expanduser("~/screenshot.jpg"), "jpg")

It can do regions too.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJrOGy9tEcVdFsyQsn8OvRAiC6bXs854nDjFCdS_C2qGb-140A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Fredrik Averpil

unread,
Oct 24, 2016, 10:19:03 AM10/24/16
to python_in...@googlegroups.com

I knew I needed to take a look at taking screenshots when this was originally posted and had saved Marcus’ excellent snippet for now. I just noticed Pixmap.grabWindow has been replaced by QScreen.grabWindow in Qt5 (PySide2/PyQt5).

So since Pixmap.grabWindow has been marked as “obsolete” you may want to take not of that: http://doc.qt.io/qt-5/qpixmap-obsolete.html

// Fredrik

Arjun Thekkummadathil

unread,
Oct 25, 2016, 12:22:45 AM10/25/16
to python_in...@googlegroups.com
I did figure out a way using PyQt, where I launch the UI in full screen and 100% transparent and use QRubberband for selection region

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

jonn

unread,
Oct 27, 2016, 5:53:30 AM10/27/16
to Python Programming for Autodesk Maya
http://www.cgdzg.com/maya-screenshot/

在 2016年10月6日星期四 UTC+8下午5:00:54,3da...@gmail.com写道:

Michał Frątczak

unread,
Apr 3, 2018, 11:01:38 AM4/3/18
to Python Programming for Autodesk Maya
Anybody has this for maya2017?
This code just blinks for nanosecond and does nothing... 
Reply all
Reply to author
Forward
0 new messages