Imagetk.photoImage无法正确显示图像
我想在tkinter GUI中显示.tif文件,但是我一直很难使图像正确加载。我能够使用image.poen ='r'正确查看图像,但是当我调用imagetk.photoimage时,它会显示一个空白的白色画布。这是代码:
def func(image_paths):
root = Tk()
im = Image.open(image_paths[0], mode='r')
im.show() # shows image correctly
im = ImageTk.PhotoImage(im)
im_label = Label(image=im)
# im_label = Label(image=ImageTk.PhotoImage(Image.open(image_paths[0], mode='r'))) # This doesn't work either
im_label.grid(row=0, column=0, columnspan=3)
root.mainloop()
任何帮助都非常感谢!
I want to show a .tif file in a tkinter gui, but I have been having trouble getting the images to load properly. I was able to view the image correctly using Image.open with mode='r', but then when I call ImageTk.PhotoImage it displays a blank white canvas. Here is the code:
def func(image_paths):
root = Tk()
im = Image.open(image_paths[0], mode='r')
im.show() # shows image correctly
im = ImageTk.PhotoImage(im)
im_label = Label(image=im)
# im_label = Label(image=ImageTk.PhotoImage(Image.open(image_paths[0], mode='r'))) # This doesn't work either
im_label.grid(row=0, column=0, columnspan=3)
root.mainloop()
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,最终工作的是该视频中的解决方案: https://www.youtube.com /watch?v = 6l6hdqywdh0
使其工作的代码线是:
So, what ended up working was the solution in this video: https://www.youtube.com/watch?v=6l6HDQyWdH0
The lines of code that got it to work was: