import tkinter as tk
root = tk.Tk()
txt = tk.Text(root)
txt.pack()
txt.tag_config('warning', background="yellow", foreground="red")
txt.insert('end', "Hello
")
txt.insert('end', "Alert #1
", 'warning')
txt.insert('end', "World
")
txt.insert('end', "Alert #2
", 'warning')
root.mainloop()