I am doing a chat client using treeview with multiple columns in Python.
This is the code for 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 these elements:
chat.insert("", "end", "", values=((user, message, time)), tags=(messageid)) chat.tag_configure(messageid, foreground='#ff0000')
Now this works fine (here is a screenshot as an example):
, but the last line of code changes the color of all three columns in this line. I want to change only the text color of column # 2 (message only), and not the entire row (not Nick or Time columns). I have been trying for a long time, but it's 4 in the morning and I give up. Is there any way to do this?
Update after 2 weeks
Now I tried to make 3 different trees (1 column each), and this ends as follows:
Although this fixes the color problem, I have a new problem: scroll bar. Is this a way to bind a scrollbar to three different tree structures? all my attempts have been failed so far, and I can only move one of the tree images using the scroll bar. Is it possible to tie 3 trees? (If yes: how ?, worth ?, should I?)
And one more problem: all attempts to remove the treeview border failed in the TTK icon.
Another problem is that now only the first word is displayed in the Mensaje tree. I donβt know why neither one nor the other: \ this is the new code about the problem with the first word.
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 post:
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 +".")