I am doing a chat client using a treeview
with multiple columns in Python.
This is the code for the treeview
:
chat = ttk.Treeview(height="26", columns=("Nick","Mensaje","Hora"), selectmode="extended")
chat.heading('#1', text='Nick', anchor=W)
chat.heading('#2', text='Mensaje', anchor=W)
chat.heading('#3', text='Hora', anchor=W)
chat.column('#1', stretch=NO, minwidth=0, width=130)
chat.column('#2', stretch=NO, minwidth=0, width=620)
chat.column('#3', stretch=NO, minwidth=0, width=65)
chat.column('#0', stretch=NO, minwidth=0, width=0) #width 0 to not display it
And I add items like this:
chat.insert("", "end", "", values=((user, message, time)), tags=(messageid))
chat.tag_configure(messageid, foreground='#ff0000')
Now, that works perfectly (here's a screenshot as an example): but that last line of code changes the colour of all 3 columns in that row. What I want is to change only the colour of the text of the #2 column (just the message) and not the entire row (not Nick or Time columns). I tried for a long time now but it's 4 AM and I surrender ☹ Is there any way to do it?
Updating 2 weeks later
Now I tried to do 3 different treeviews (1 column each) and it ends up this way: Although that fix the colour issue, i have a new issue: The scrollbar. It's there a way to bound a scrollbar to 3 different treeviews? all my attemps had failed so far and i can move only one of the treeview with a scrollbar. It's possible to bound to 3 treeviews? (If yes: how?, worth?, should i?)
And also another problem: all attempts to remove treeview border have failed in TTK python.
Another problem is that now the Mensaje treeview only displays the first word. No idea why neither :\ this is the new code about the first word issue.
chat2 = ttk.Treeview(height="28", columns="Mensaje", selectmode="extended")
chat2.heading('#1', text='Mensaje', anchor=CENTER)
chat2.column('#1', stretch=NO, minwidth=400, width=620)
chat2.column('#0', stretch=NO, minwidth=0, width=0)
And this goes on message:
BotGUI.chat2.insert("", "end", iid=(idmensajeactual), values=mensaje, tags=(messageid))
try:
BotGUI.chat2.tag_configure(messageid, foreground='#'+colorfuente) #tfl
except TclError:
print("[Error02] - can't assign colour of "+ usuario +".")