2

I'm trying to change the color of a line in a textbox to a hex code without affecting the rest of the lines. I've tried using insert tags but they change the previous lines as well. Is there a way to achieve my goal? | What I'm trying to achieve |

Heres my current code:

def receivemessages():
      ...
      elif message[0:1] == "#":
            color = message[0:7]
            message = message[7:]
            entry_2.config(state=tkinter.NORMAL)
            entry_2.tag_config('usermessage', foreground=color)
            entry_2.insert(tkinter.END, message + '\n', 'usermessage')
            entry_2.see("end")
            entry_2.config(state=tkinter.DISABLED)

| What I get |

tags are probably the wrong thing to use here but I'm failing to find other solutions online. if someone can point me in the right direction it would be much appreciated.

Itayo
  • 21
  • 2
  • Welcome to [so]. We are here to help with code that dosent work. If you ask a question, it will be important to share a bit of code, ideally a [mre]. Otherwise you asking us to write your code and [so] isnt a code writing service. Please take the time for the [tour] and [ask]. – Thingamabobs Apr 01 '22 at 08:15
  • @Thingamabobs Thank you! I've added my current code to the question. – Itayo Apr 01 '22 at 08:43
  • It is because you have used same tag "usermessage". Try using `color` as the tag instead. – acw1668 Apr 01 '22 at 09:11
  • @acw1668 This solved my problem! Thank you! – Itayo Apr 01 '22 at 09:21

0 Answers0