• Tk colors

    From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Thu Aug 7 21:47:23 2025
    From Newsgroup: comp.lang.tcl

    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
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Aug 7 16:05:37 2025
    From Newsgroup: comp.lang.tcl

    On 8/7/2025 3:47 PM, Helmut Giese 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
    Helmut


    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


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 7 20:06:45 2025
    From Newsgroup: comp.lang.tcl

    At Thu, 07 Aug 2025 21:47:23 +0200 Helmut Giese <hgiese@ratiosoft.com> 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
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Thu Aug 7 23:00:46 2025
    From Newsgroup: comp.lang.tcl

    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.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Aug 7 17:35:59 2025
    From Newsgroup: comp.lang.tcl

    On 8/7/2025 5:00 PM, Schelte wrote:

    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.

    This piece of code is quite old. Thanks for the info though, I didn't
    know that.



    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Sun Aug 10 15:44:56 2025
    From Newsgroup: comp.lang.tcl

    Sorry for the delay.
    Thanks to all of you.
    Robert, 'winfo rgb' was exactly what I was looking for.
    Helmut
    --- Synchronet 3.21a-Linux NewsLink 1.2