In Python, if I want to open/launch the default browser using shell, I can import os and execute run "www.google.com". Is there any similar way to open the print pictures dialog for a given image.jpg as if right clicking it and selecting print in the context menu that I can use to call this routine from python???
Thank you.
You can call
win32api.ShellExecute
with the"print"
verb. An example: http://timgolden.me.uk/python/win32_how_do_i/print.htmlAt least on my Windows system (Windows 7), there seems to be no trivial way to achieve this. I found that a naive call to ShellExecute appeared to do nothing. Then I tried this:
With the addition of the call to
sleep()
the dialog appeared, but when the python process terminated, the print dialog closed too.Since the print dialog runs in-process I don't see an easy wait to wait on it. If it were to run as a separate process then it would be trivial to wait on that process.
I suppose a hacky solution would be to run this through
pythonw
so that no console appeared, and put in a long sleep. You might end up with some stray Python processes that were aimlessly sleeping, but that might not matter.