【发布时间】:2018-05-13 18:12:17
【问题描述】:
我正在 Python tkinter 库中创建树视图。我想在代表文件的每个节点旁边都有一个图像图标。我已经创建了函数,但我不知道为什么图像只出现在最后一个节点中。
def populate_tree(self, parent, fullpath, children):
for child in children:
cpath = os.path.join(fullpath, child).replace('\\', '/')
if os.path.isdir(cpath):
cid = self.tree.insert(parent, END, text=child,
values=[cpath, 'directory'])
self.tree.insert(cid, END, text='dummy')
else:
if (child != "Thumbs.db"):
self.pic = ImageTk.PhotoImage(file=cpath)
self.tree.insert(parent, END, text=child, image=self.pic,
values=[cpath, 'file','{} bajtów'.format(os.stat(cpath).st_size)])
如果下一个节点扩展则消失...
【问题讨论】: