I am doing a program to make a General Balance which in total are 10 columns. I'm trying to use Tkinter's Treeview() function but it only shows me 2 of those columns. How would it be to show all?
Here is the piece of code:
def balance(self):
# Ventana de balance
self.balance_wind = Toplevel()
self.balance_wind.title('Balance de 8 columnas')
# Table
self.tree = ttk.Treeview(self.balance_wind, height=10, columns=10)
self.tree.grid(row=0, column=0)
self.tree.heading('#0', text='Numero', anchor=CENTER)
self.tree.heading('#1', text='Cuenta', anchor=CENTER)
self.tree.heading('#2', text='Debe', anchor=CENTER)
self.tree.heading('#3', text='Haber', anchor=CENTER)
self.tree.heading('#4', text='Deudor', anchor=CENTER)
self.tree.heading('#5', text='Acreedor', anchor=CENTER)
self.tree.heading('#6', text='Activo', anchor=CENTER)
self.tree.heading('#7', text='Pasivo', anchor=CENTER)
self.tree.heading('#8', text='Positivo', anchor=CENTER)
self.tree.heading('#9', text='Negativo', anchor=CENTER)
It is a very typical error and very understandable by the way, the argument
columns
is not used to indicate the number of columns that you want theTreeView
, not directly through an integer. Instead it expects a sequence of strings (str
) with identifiers for each column. The identifiers will be used internally to identify the columns, keeping in mind that the first column always has '# 0' as identifier, the ones you add withcolumns
will be added to this first column.When doing
columns=10
what you do is add a single column apart from"#0"
with"3"
as identifier, result, two columns only.If you want to use column
#0
, you need to pass a list with nine strings as the identifier, which will make a total of ten columns.If you want to drop the first column you can instead do the following: