Python 打开并显示从本地文件夹中选择的图像
我是Python的新手,我想创建一个简单的程序,用户可以在其中打开并显示从本地文件夹中选择的图像(png)Python 打开并显示从本地文件夹中选择的图像,python,image,tkinter,Python,Image,Tkinter,我是Python的新手,我想创建一个简单的程序,用户可以在其中打开并显示从本地文件夹中选择的图像(png) def imageopen(): root.filename = filedialog.askopenfilename(initialdir="/", title="Select file", filetypes=(("png files", "*.png"), ("al
def imageopen():
root.filename = filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("png files", "*.png"), ("all files", "*.*")))
print(root.filename)
button = Button(text="Open Image", width=30, command=imageopen).pack()
所以我有上面的代码从本地选择任何图像,它返回图像的路径作为结果。我的问题是,如何使用路径显示图像
提前感谢您的帮助。您可以使用枕头,因为它预装在anaconda中。只需执行以下操作:
from PIL import Image
my_image=Image.open("path/to/IMAGE/file")
my_image.show()
相关的谢谢,在我完成了我的_image=image.open(root.filename):)之后,它就工作了