Home > database >  Color some text in a Tkinter Label
Color some text in a Tkinter Label

Time:10-22

I wanna color just an * in red on a Tkinter label, to indicate that that field is required. I have tried the following:

import colorama
from colorama import Fore, Style

colorama.init()
date_label = Label(my_frame, text=f"Date: {Fore.RED} * {Style.RESET_ALL})"
date_label.pack()

And this is the output:

Date: [][31m*

I know that you can color a label with fg, but i wanna try just coloring the asterisk.

I have also tried the ANSI codes ans it gives the same output.

I'm on Windows btw.

CodePudding user response:

You can try combining 2 Label in different color:

from tkinter import *

Root = Tk()

Date = Label(Root, text="Date: ", fg="black")
Asterick = Label(Root, text="*", fg="red")
Date.grid(row=0, column=0)
Asterick.grid(row=0, column=1)
Root.mainloop()

*No need for colorama

  • Related