如何从 tkinter 中的选定行获取数据?

How to get the data from selected row in tkinter?

我已经在 tkinter 中创建了树视图,列代码在这里

        self.treeview = ttk.Treeview(self.treeviewFrame)
        self.treeview['columns'] = ('1','2','3','4','5','6','7')

        self.treeview.column('#0',width=50,minwidth=25)
        self.treeview.column('1',width=50,minwidth=25,anchor=W)
        self.treeview.column('2',width=50,minwidth=25,anchor=W)
        self.treeview.column('3',width=50,minwidth=25,anchor=W)
        self.treeview.column('4',width=50,minwidth=25,anchor=W)
        self.treeview.column('5',width=50,minwidth=25,anchor=W)
        self.treeview.column('6',width=50,minwidth=25,anchor=W)
        self.treeview.column('7',width=50,minwidth=25,anchor=W)


        self.treeview.bind('<ButtonRelease-1>',self.selectedRow)

        self.treeview.pack(fill=BOTH,expand=1)
        self.treeViewData()

为了检索选定的行,我使用了以下代码

self.treeview.bind('<ButtonRelease-1>',self.selectedRow)

def selectedRow(self,a):
        self.curItem = self.treeview.focus()
        self.contents = self.treeview.item(self.curItem)
        print(self.contents['values'])

在打印内容[值] 时,我命名为 S.No 的第一行 #0 未打印。有没有办法从 #0

中检索这些值

有八列,但只打印了 7 个值。第一行不打印。请帮助我!

第 0 列是默认的,通常由选项文本填充。所以我猜 #0 不是一个值。

尝试在此行之前添加 print(self.contents['text']) print(self.contents['values']) 看看。