【问题标题】:"Item . not found" with ttk.Treeview().insert()带有 ttk.Treeview().insert() 的“项目。未找到”
【发布时间】:2015-08-20 19:46:04
【问题描述】:

我正在尝试在具有五列的 tkinter 树视图中插入项目。我正在使用这行代码:

self.resultsTable.insert(parent=self.parent, index='end', values=['1','2','3','4','5'])

但是,解释器显示以下内容:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\gigi\Desktop\me\projects\PyMusic\test\threaded_test.py", line 166, in searchMusic
    self.showResults()
  File "C:\Users\gigi\Desktop\me\projects\PyMusic\test\threaded_test.py", line 111, in showResults
    self.resultsTable.insert(parent=self.parent, index='end', values=['1','2','3','4','5']) # values=song['details']
  File "C:\Python34\lib\tkinter\ttk.py", line 1337, in insert
    res = self.tk.call(self._w, "insert", parent, index, *opts)
_tkinter.TclError: Item . not found

我在网上搜索了很多解决方案,但找不到。有没有使用过 tkinter 的人可以帮助我?

【问题讨论】:

  • 什么是self.parent?它是以前添加的项目的 id 吗?
  • @BryanOakley self.parent 是主/根级窗口。我误解了 insert() 方法中那个“父”关键字参数的含义。我认为它指的是树视图的父小部件。我相应地更正了代码行,将 parent=self.parent 替换为 parent='',以便添加新的独立项(= 新行)。

标签: python user-interface tkinter treeview


【解决方案1】:

我的猜测是您的self.parent 代表根窗口,它的字符串表示为“.”。树告诉您它在树中没有任何 ID 为 "." 的项目。

insert 的第一个参数不是小部件。它应该是空字符串 - 代表树中 的根项的 id - 或之前插入的项的 id。

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 2015-10-05
    • 2018-07-13
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    相关资源
    最近更新 更多