StarCoder17
StarCoder17

Reputation: 175

How to create a colored font in tcl

I am making a canvas with black background. These canvas have some rectangles and text attached to it. I wanted to use white color of text fonts instead of default black. But since font didn't have an option of using color i am not sure what to be done to change color of text. I am creating text like this.

.c create text $i $j -text "($i,$j)" -anchor ne -font fontTEMP_varwidth

font create fontTEMP_varwidth \
   -family {comic sans ms} \
      -size -10 \
         -weight bold \
         -col
            -slant roman

Upvotes: 0

Views: 1120

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137707

Fonts themselves aren't coloured (Tk considers them to be purely about the shape of the letters), but you can set the colour to use elsewhere. In particular, the canvas widget's text item type supports the standard -fill option, which is the colour used to render the text in the item:

.c create text $i $j -text "($i,$j)" -anchor ne -font fontTEMP_varwidth -fill red

If you were using a text widget, you'd usually set the colour along with the font on the tag applied to the text. (Or you'd set the default for the entire widget.)

Upvotes: 2

Related Questions