Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么移动我的图像而不是创建多个图像_Python_Tkinter - Fatal编程技术网

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)
帮助您的助手使用