我正在尝试使用ttkwidget中的CheckboxTreeview将复选框放在treeview的每一行前面,我使用了一个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()它用复选框建立了一棵空白树。空复选框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()标准树视图正确显示,如果我尝试将列和头信息添加到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查询填充树视图时,如何获得树视图中行前面的复选框?
发布于 2020-07-01 21:06:05
线
tree = CheckboxTreeview(root, column=("column1", "column2"), show='headings')需要的是
tree = CheckboxTreeview(root, column=("column1", "column2"), show=("headings", "tree"))复选框位于0位置。
https://stackoverflow.com/questions/62665421
复制相似问题