PIL image show() doesn't work on windows 7

我与影子孤独终老i 提交于 2019-11-27 23:25:23

问题


I would like to show an image using python on windows and other platforms. When I do:

from PIL import Image
im = Image.open('image.png')
im.show()

my default viewer opens up and tells me that Windows Photo Viewer can't open this picture because either this file was deleted , etc.

The file is probably deleted because PIL calls the os with the following command: "start /wait %s && del /f %s" % (file, file)

I found a workaround here. They recommend changing PIL's code to "start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file). However, I want others to be able to use my code.

Is there a simple solution? Should I look for an alternative to PIL that would work crossplatform?


回答1:


Ok, found a solution here:

import webbrowser
webbrowser.open('image.png')

It opens the default viewer, not the browser, on my machine.

Also, there is os.startfile.




回答2:


If you want it to be opened by MS paint only, you can use:

start /wait mspaint %s && del /f %s" % (file, file)

The /wait is not having any effect when the file name is specified directly.




回答3:


When Photo Viewer does appear, Go to menu on top ->Open->Choice Program-> Select Paint
On Spanish -> Abrir-> Elegir Programa -> seleccionar Paint

image reference: image



来源:https://stackoverflow.com/questions/7715501/pil-image-show-doesnt-work-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!