Reputation: 1734
I will be honest here and say that I'm playing with the treeviews and ttk without really understand how it works. Nevertheless, I'm getting some issues and after Googling for it I can't find a proper way to fix it. I use treeviews as listbox, since ttk doesn't have a listbox element.
1: Issue 1: somehow I got an extra column all the time, why?
chat = ttk.Treeview(height="26", columns=("Nick","Mensaje","Hora"), selectmode="extended")
chat.heading('#0', text='Nick', anchor=W)
chat.heading('#1', text='Mensaje', anchor=W)
chat.heading('#2', text='Hora', anchor=W)
chat.column('#0', stretch=NO, minwidth=0, width=100)
chat.column('#1', stretch=NO, minwidth=0, width=510)
chat.column('#2', stretch=NO, minwidth=0, width=100)
chat.place(bordermode=OUTSIDE, x=5, y=45)
But that adds an extra column at the end so i had to add to fix it:
chat.column('#3', stretch=NO, minwidth=0, width=0)
Issue 2: While I'm trying to insert items to the treeview
, I realized I can't find a way to say where the info should go. For example I want a variable to fill column1
but another variable to fill column2
. As far as I could go was:
chat.insert('', "end", '', text=message)
But that would only add the message on the column0
. How do i make it saves it on column1
while another var is saved on column0
?
Thank you for your answers.
Edit: i was tring to do something like this: http://pdqi.com/w/Download/BLT/treeview1.gif or http://zoomq.qiniudn.com/ZQScrapBook/ZqFLOSS/data/20100928164510/multicolumn_treeview_plastiktheme.png
Upvotes: 0
Views: 1265
Reputation: 35
For issue 1: I suggest you to rewrite your code:
chat = ttk.Treeview(height="26", columns=("Mensaje", "Hora"))
chat.heading('#0', text='Nick', anchor=W)
chat.heading('Mensaje', text='Mensaje', anchor=W)
chat.heading('Hora', text='Hora', anchor=W)
chat.column('#0', stretch=NO, minwidth=0, width=100)
chat.column('Mensaje', stretch=NO, minwidth=0, width=510)
chat.column('Hora', stretch=NO, minwidth=0, width=100)
For issue 2: Use
chat.insert('', 'end', 'iid_1')
chat.set('iid_1', 'Hora', 'your value')
For issue 3: There is not presently a listbox in ttk, but you can use Listboxes from the classic Tk widgets.
Upvotes: 3