繁体   English   中英

PIL图像show()在Windows 7上不起作用

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

我想在Windows和其他平台上使用python显示图像。 当我做:

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

我的默认查看器打开并告诉我Windows Photo Viewer can't open this picture because either this file was deleted等。

该文件可能已删除,因为PIL使用以下命令调用操作系统: "start /wait %s && del /f %s" % (file, file)

我在这里找到了解决方法。 他们建议将PIL的代码改为"start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file) 但是,我希望其他人能够使用我的代码。

有简单的解决方案吗? 我应该寻找可以在跨平台上工作的PIL的替代方案吗?

好的,在这里找到了解决方案:

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

它在我的机器上打开默认查看器,而不是浏览器。

另外,还有os.startfile

如果您只想通过MS paint打开它,您可以使用:

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

直接指定文件名时, /wait没有任何影响。

当Photo Viewer出现时,转到顶部的菜单 - >打开 - >选择程序 - >选择绘画
西班牙语 - > Abrir-> Elegir Programa - > seleccionar Paint

图像参考: 图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM