mardi 30 juin 2020

CheckboxTreeview not showing checkboxes when using SQLite query populate the rows

I'm trying to use the CheckboxTreeview from ttkwidgets to put checkboxes in front of each line of a treeview I populate with an SQLite query. This is my code:

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()

It puts up a blank tree with checkboxes. empty checkbox treeview I can verify that the command is working properly because I do get this printed out in the console

(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')

But a standard Treeview works

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 and if I try to add the column and header info to the CheckboxTreeview version it looks the same as the standard ttk.Treeview version

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()

How do I get checkboxes in front of the rows in a treeview when I fill the tree view via an SQLite query?




Aucun commentaire:

Enregistrer un commentaire