不了解此tkinter.TclError

时间:2019-03-21 14:58:32

标签: python tkinter

我似乎无法将我先前创建的列设置(更新)为单击按钮时会调用的函数的值,它表示未找到项目。

curItem = tree.focus()
contents =(tree.item(curItem))
selecteditem = contents['values']
tree.get_children(curItem)
Database()
cursor.execute("SELECT SUM(PRODUCT_QTY) FROM `product` WHERE `product_id` = %d" % selecteditem[0])
fetch = cursor.fetchall()
for data in fetch:
   # d = tree.item(data)
    tree.set(selecteditem, 3, data)
    a = data
conn.commit()
cursor.close()
conn.close()

错误和回溯:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\.\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py",
     line 1705, in __call__ return self.func(*args)
File "c:\Users\.\Desktop\Simple_Inventory PYTHON\Simple Inventory System\index.py",
      line 268, in calculate tree.set(selecteditem, 2, data)
File "C:\Users\.\AppData\Local\Programs\Python\Python37-32\lib\tkinter\ttk.py",
      line 1482, in set res = self.tk.call(self._w, "set", item, column, value)
      _tkinter.TclError: Item 8 e 3 4 not found

注意:8是商品的ID,名称是3,而4是价格和数量(虚拟值)

2 个答案:

答案 0 :(得分:0)

您正在将selecteditem设置为某些tree.set的参数必须是 identifier 。就像错误所说的那样,树中没有任何8 e 3 4的ID。

标识符将是您调用tree.insert时返回的任何内容。它要么是为您计算的“ IXXX”形式的标识符(例如:I001),要么是您在调用tree.insert时指定的任何标识符。

由于您没有显示如何在树中创建项目,因此很难说出该值是多少。使用curItem可能就足够了,但是从您提供的一小段代码来看,很难确定。

答案 1 :(得分:0)

对于那些可能会遇到相同问题的人,只需将selectedItem[0]而不是tree.set()放在ListView参数中即可解决此问题。只需在其中放入聚焦的树变量即可。