我正在尝试在 python 3.2 上使用 tkinter 来显示来自 Internet 的图像。
我收到 TypeError: 'HTTPResponse' object is not callable。我知道这意味着我错误地引用了一个变量或函数。我已阅读urllib “模块对象不可调用”,但我仍然不确定如何解决此问题。感谢您的帮助。
import tkinter as tk
from urllib.request import urlopen
from PIL import ImageTk, Image
#http://docs.activestate.com/activepython/3.1/diveintopython3/html/porting-code- to-python-3-with-2to3.html
import io
img_file = urlopen('https://www.google.com/images/srpr/logo4w.png')
im = io.FileIO(img_file())<<<<<<<<<<<<<this line is throwing the error
resized_image = Image.open(im)
im.show()
root = tk.Tk()
img = ImageTk.PhotoImage(resized_image)
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()