[英]In Python, how can I open a file and read it on one line, and still be able to close the file afterwards?
[英]How to open an image in Python and close afterwards?
Python 版本:3.7.9
我試過將 Pillow/PIL 與 show() 和 close() 一起使用,但是這只會關閉命令提示符並使文件查看器仍然打開。
我試過 subprocess Popen 但這只是給我錯誤“系統找不到指定的文件”,即使文件是正確的。 所以我現在被困住了。 我認為這對 Python 來說是一個簡單的過程。
我只是想打開一個圖像,然后在用戶點擊一個按鈕后,能夠關閉它。
對建議/圖書館開放。 謝謝!
只需調用此函數,就會彈出一個帶有圖像的新窗口。 在窗口關閉之前,您的代碼不會被執行。
import tkinter
from PIL import ImageTk, Image
def image_preview (path):
root = tkinter.Tk ()
root.title ("Preview")#Modify this to change the title
img = ImageTk.PhotoImage(Image.open(path))
panel = tkinter.Label (root, image = img)
panel.pack ()
root.mainloop ()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.