Python 为什么移动我的图像而不是创建多个图像
我正在尝试使用以下方法在新打开的窗口的几个位置显示相同的图像:Python 为什么移动我的图像而不是创建多个图像,python,tkinter,Python,Tkinter,我正在尝试使用以下方法在新打开的窗口的几个位置显示相同的图像: root = tkinter.Tk() w, h = root.winfo_screenwidth(), root.winfo_screenheight() root.geometry("%dx%d+0+0" % (w, h)) for i in range(len(entities) + 1): img = ImageTk.PhotoImage(Image.open(path)) panel = tkinter.Labe
root = tkinter.Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
for i in range(len(entities) + 1):
img = ImageTk.PhotoImage(Image.open(path))
panel = tkinter.Label(root, image = img)
panel.grid(row = i, column = i)
这确实显示了第一个图像,但只是将其移动,而不是创建新图像。我怎样才能修复它?找到了
我改为使用列表来存储图像,然后将代码更改为:
entity_images = []
for i in range(len(entities)):
img = ImageTk.PhotoImage(Image.open(path))
entity_images.append(img)
panel = tkinter.Label(root, image = entity_images[i])
panel.grid(row = i, column = i)
帮助您的助手使用