• canvas: change the background of a text item

    From Ralf Fassel@21:1/5 to All on Wed Oct 30 13:00:43 2024
    Is there a way to change the background of a text item on a canvas?
    I can change the color of the text via -fill, but I found no way to
    change the background color of the text:

    pack [canvas .c] -fill both -expand yes
    # red text on yellow background
    .c create text 100 100 -text "Example text" -font {Helvetica 20} -fill red

    how to change the background of the text field to yellow?
    i.e. the same as ".c configure -background yellow", but restricted
    to the area of the text.

    TNX
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Wed Oct 30 14:42:02 2024
    * Ralf Fassel <[email protected]>
    | Is there a way to change the background of a text item on a canvas?
    | I can change the color of the text via -fill, but I found no way to
    | change the background color of the text:

    | pack [canvas .c] -fill both -expand yes
    | # red text on yellow background
    | .c create text 100 100 -text "Example text" -font {Helvetica 20} -fill red |
    | => how to change the background of the text field to yellow?
    | i.e. the same as ".c configure -background yellow", but restricted
    | to the area of the text.

    Ok, found a workaround on the WIKI:

    https://wiki.tcl-lang.org/page/canvas+text

    - create a rectangle with the bbox of the text and lower it beneath
    the text.

    Somehow the 'rectangle' item was not there when I scanned the canvas
    manpage earlier :-/

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From undroidwish@21:1/5 to Ralf Fassel on Wed Oct 30 20:29:38 2024
    On 10/30/24 14:42, Ralf Fassel wrote:

    Ok, found a workaround on the WIKI:

    https://wiki.tcl-lang.org/page/canvas+text
    ...

    thanks for digging, that's intriguing. The XLFD allowed in ancient times
    for transformations, didn't know that. Not that it is relevant for now,
    since we all render our texts in Tk using libxft. But until 2.3.5, that library, too, had still problems scaling/rotating/translating
    bitmap fonts (especially the color emojis).

    - create a rectangle with the bbox of the text and lower it beneath
    the text.

    And yes, the challenge now is to make the rectangle (ahem, rotated, a
    polygon) for a somewhat rotated text out of its bbox (if you'd like to
    have a text background).

    And please, enhance the wiki in this regard.

    BR,
    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)