Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...