Answer the question
In order to leave comments, you need to log in
How to display data only in certain columns of Treeview (Tkinter)?
Good afternoon!
Faced with the problem of displaying data from the database in Treeview. The problem is that there are three tables in the database: Students, Teachers and Other visitors, when data is displayed from the Students table, everything is OK, but when data is output from the other two, the fields that should be empty (Class and Letter) are filled in. How can I make it populate only the columns I need in a Treeview?
Part of the code is attached:
#Таблица
self.table = ttk.Treeview(self, columns=('FIO','DB','Class','litera','phone','adr','book','aut','stat'), height=100, show='headings')
self.table.column('FIO', width=100, anchor=tk.CENTER)
self.table.column('DB', width=100, anchor=tk.CENTER)
self.table.column('Class', width=100, anchor=tk.CENTER)
self.table.column('litera', width=100, anchor=tk.CENTER)
self.table.column('phone', width=100, anchor=tk.CENTER)
self.table.column('adr', width=100, anchor=tk.CENTER)
self.table.column('book', width=100, anchor=tk.CENTER)
self.table.column('aut', width=100, anchor=tk.CENTER)
self.table.column('stat', width=100, anchor=tk.CENTER)
self.table.heading('FIO', text='ФИО')
self.table.heading('DB', text='День рождения')
self.table.heading('Class', text='Класс')
self.table.heading('litera', text='Литера')
self.table.heading('phone', text='Телефон')
self.table.heading('adr', text='Адрес')
self.table.heading('book', text='Книга')
self.table.heading('aut', text='Автор')
self.table.heading('stat', text='Статус')
self.table.pack()
self.table.place(x=0,y=100)
conn = sqlite3.connect(os.path.dirname(os.path.abspath(__file__))+"/LC.db")
cur = conn.cursor()
#Вывовд всех учеников
cur.execute("SELECT * FROM STUD")
rows = cur.fetchall()
for row in rows:
self.table.insert("" , tk.END , values=row)
#Вывод всех учителей
cur.execute("SELECT * FROM TEACH")
rows = cur.fetchall()
for row in rows:
self.table.insert("" , tk.END , values=row)
#Вывод других посетителей
cur.execute("SELECT * FROM OTHERS_VISITERS")
rows = cur.fetchall()
for row in rows:
self.table.insert("" , tk.END , values=row)
Answer the question
In order to leave comments, you need to log in
In short, I solved the problem myself. Added to the database columns that are NOT NULL. And then empty data is added to these columns, as a result of which these columns are also empty in the Treeview
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question