• Re: Tk colors

    From Robert Heller@21:1/5 to [email protected] on Thu Aug 7 20:06:45 2025
    At Thu, 07 Aug 2025 21:47:23 +0200 Helmut Giese <[email protected]> wrote:


    Hello out there,
    is there a function to turn Tk colors' names (like red or chocolate)
    into their rgb equivalents?
    Thanks for any hints

    winfo rgb window color

    For example:

    % winfo rgb . green
    0 32896 0
    % winfo rgb . orange
    65535 42405 0
    % winfo rgb . red
    65535 0 0
    % winfo rgb . chocolate
    53970 26985 7710



    Helmut



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to saito on Thu Aug 7 23:00:46 2025
    On 07/08/2025 22:05, saito wrote:
    This is what I use:

    lassign [winfo rgb . $c] r g b
    set r [expr {$r % 256}]
    set g [expr {$g % 256}]
    set b [expr {$b % 256}]
    format "\#%02x%02x%02x" $r $g $b

    Interesting choice to use the least significant byte of the color
    values. It happens to work as long as both bytes are the same, which
    they seem to be for now. But I would have picked the most significant
    byte myself, just in case there may be graphics cards in the future with
    more than 8 bits per color.

    Within Tk it's also perfectly valid to specify an rgb value with 4 hex
    chars per color. So for that use case you could just simplify to:
    format #%04x%04x%04x {*}[winfo rgb . $c]


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Thu Aug 7 21:47:23 2025
    Hello out there,
    is there a function to turn Tk colors' names (like red or chocolate)
    into their rgb equivalents?
    Thanks for any hints
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Sun Aug 10 15:44:56 2025
    Sorry for the delay.
    Thanks to all of you.
    Robert, 'winfo rgb' was exactly what I was looking for.
    Helmut

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