复选框树视图在使用 SQLite 查询时不显示复选框填充行



我正在尝试使用ttkwidgets中的CheckboxTreeview将复选框放在我用SQLite查询填充的树视图的每一行前面。这是我的代码:

from ttkwidgets import CheckboxTreeview
import tkinter as tk
import sqlite3
root = tk.Tk()
tree = CheckboxTreeview(root)
connection = sqlite3.connect('lambtracker_db.sqlite')
cursor = connection.cursor()
cmd = "select id_deathreasonid, death_reason from death_reason_table"
cursor.execute(cmd)
rows = cursor.fetchall()
for row in rows:
print(row)
tree.insert('', 'end', values=row)
tree.pack()
root.mainloop()

它放置了一个带有复选框的空白树。 空复选框树视图 我可以验证该命令是否正常工作,因为我确实在控制台中打印了它

(1, 'Died Unknown')
(2, 'Died Old Age')
(3, 'Died Predator')
(4, 'Died Illness')
(5, 'Died Injury')
(6, 'Died Stillborn')
(7, 'Died Birth Defect')
(8, 'Died Meat')
(9, 'Died Euthanized')
(10, 'Died Dystocia')
(11, 'Died Other')
(12, 'Died Culled')

但是标准的树视图有效

import tkinter as tk
from tkinter import ttk
import sqlite3
root = tk.Tk()
tree = ttk.Treeview(root, column=("column1", "column2"), show='headings')
tree.heading("#1", text="id_deathreasonid")
tree.heading("#2", text="Death Reason")
connection = sqlite3.connect('lambtracker_db.sqlite')
cursor = connection.cursor()
cmd = "select id_deathreasonid, death_reason from death_reason_table"
cursor.execute(cmd)
rows = cursor.fetchall()
for row in rows:
print(row)
tree.insert('', 'end', values=row)
tree.pack()
root.mainloop()

标准树视图正确显示 如果我尝试将列和标题信息添加到复选框树视图版本,它看起来与标准 ttk 相同。树视图版本

from ttkwidgets import CheckboxTreeview
import tkinter as tk
import sqlite3
root = tk.Tk()
tree = CheckboxTreeview(root, column=("column1", "column2"), show='headings')
tree.heading("#1", text="id_deathreasonid")
tree.heading("#2", text="Death Reason")
connection = sqlite3.connect('lambtracker_db.sqlite')
cursor = connection.cursor()
cmd = "select id_deathreasonid, death_reason from death_reason_table"
cursor.execute(cmd)
rows = cursor.fetchall()
for row in rows:
print(row)
tree.insert('', 'end', values=row)
tree.pack()
root.mainloop()

当我通过 SQLite 查询填充树视图时,如何在树视图中的行前面获取复选框?

tree = CheckboxTreeview(root, column=("column1", "column2"), show='headings')

需要

tree = CheckboxTreeview(root, column=("column1", "column2"), show=("headings", "tree"))

复选框位于位置 0。

最新更新