CheckboxTreeview 在使用 SQLite 查询填充行时不显示复选框
CheckboxTreeview not showing checkboxes when using SQLite query populate the rows
我正在尝试使用 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()
它建立了一个带有复选框的空白树。
empty checkbox treeview
我可以验证该命令是否正常工作,因为我确实在控制台中打印了它
(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')
但标准的 Treeview 有效
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()
standard treeview showing up properly
如果我尝试将列和 header 信息添加到 CheckboxTreeview 版本,它看起来与标准 ttk.Treeview 版本
相同
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。
我正在尝试使用 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()
它建立了一个带有复选框的空白树。 empty checkbox treeview 我可以验证该命令是否正常工作,因为我确实在控制台中打印了它
(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')
但标准的 Treeview 有效
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()
standard treeview showing up properly 如果我尝试将列和 header 信息添加到 CheckboxTreeview 版本,它看起来与标准 ttk.Treeview 版本
相同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。