• Named colours in Tk

    From Alan Grunwald@nospam.nurdglaw@gmail.com to comp.lang.tcl on Mon May 19 15:05:20 2025
    From Newsgroup: comp.lang.tcl

    Tk recognises a lot of colour names, as documented at, say, https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to
    get a list of them?

    I guess I could hack it out of one of the source files, but I'd hope to
    be able to get it in a cleaner fashion.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon May 19 17:35:46 2025
    From Newsgroup: comp.lang.tcl

    * Alan Grunwald <nospam.nurdglaw@gmail.com>
    | Tk recognises a lot of colour names, as documented at, say,
    | https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible
    | to get a list of them?

    | I guess I could hack it out of one of the source files, but I'd hope
    | to be able to get it in a cleaner fashion.

    That would probably be xlib/xcolors.c with a very tricky table and
    binary search algo.

    Note that the plain text doc/colors.n contains at least one error
    ('agua' vs 'aqua').

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ian@gay@sfuu.ca to comp.lang.tcl on Mon May 19 09:49:11 2025
    From Newsgroup: comp.lang.tcl

    Alan Grunwald wrote:

    Tk recognises a lot of colour names, as documented at, say, https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible
    to get a list of them?

    I guess I could hack it out of one of the source files, but I'd hope
    to be able to get it in a cleaner fashion.

    They're listed in the Tk html docs under 'colors'.
    --
    *********** To reply by e-mail, make w single in address **************
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Mon May 19 18:04:47 2025
    From Newsgroup: comp.lang.tcl

    Are these colors any different from the X11 colors, listed in /usr/share/X11/rgb.txt ?
    At Mon, 19 May 2025 09:49:11 -0700 Ian <gay@sfuu.ca> wrote:

    Alan Grunwald wrote:

    Tk recognises a lot of colour names, as documented at, say, https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible
    to get a list of them?

    I guess I could hack it out of one of the source files, but I'd hope
    to be able to get it in a cleaner fashion.

    They're listed in the Tk html docs under 'colors'.
    --
    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 Ian@gay@sfuu.ca to comp.lang.tcl on Mon May 19 17:11:00 2025
    From Newsgroup: comp.lang.tcl

    Robert Heller wrote:

    Are these colors any different from the X11 colors, listed in /usr/share/X11/rgb.txt ?

    Hard to compare, the ordering is different. They look pretty similar superficially.


    At Mon, 19 May 2025 09:49:11 -0700 Ian <gay@sfuu.ca> wrote:


    Alan Grunwald wrote:

    Tk recognises a lot of colour names, as documented at, say,
    https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it
    possible to get a list of them?

    I guess I could hack it out of one of the source files, but I'd
    hope to be able to get it in a cleaner fashion.

    They're listed in the Tk html docs under 'colors'.

    --
    *********** To reply by e-mail, make w single in address **************
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Mon May 19 19:51:38 2025
    From Newsgroup: comp.lang.tcl

    On 5/19/2025 7:05 AM, Alan Grunwald wrote:
    Tk recognises a lot of colour names, as documented at, say, https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to get a list of them?

    I guess I could hack it out of one of the source files, but I'd hope to be able to get it in a cleaner fashion.

    What sort of format do you want? Are there others that this page doesn't document?

    I displayed the above link in FF, and then did a click, move pointer to end, shift click, copy, paste into my editor, and made a text file, a:/colors.txt. There were 8360 lines, looking like:

    alice blue


    240


    248


    255

    AliceBlue


    240


    248


    255

    ...


    YellowGreen


    154


    205


    50

    So, each color took up 11 lines, and multi-word names appeared on a single line. So, exactly 760 colors on that page.

    Very easy to process with a small tcl script. I didn't look at the system specific colors however.


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Tue May 20 10:03:52 2025
    From Newsgroup: comp.lang.tcl

    On 19/05/2025 20:04, Robert Heller wrote:
    Are these colors any different from the X11 colors, listed in /usr/share/X11/rgb.txt ?

    Yes, there are a few small differences. See tip 403: https://core.tcl-lang.org/tips/doc/trunk/tip/403.md


    Schelte.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Tue May 20 10:32:39 2025
    From Newsgroup: comp.lang.tcl

    Am 19.05.2025 um 16:05 schrieb Alan Grunwald:
    Tk recognises a lot of colour names, as documented at, say, https:// www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to get a
    list of them?

    I guess I could hack it out of one of the source files, but I'd hope to
    be able to get it in a cleaner fashion.

    Alan,
    this is a long awaited low hanging fruit in Tk.
    An "tkinfo colornames" should be implemented.

    I would love to use it in colour chooser dropdown boxes etc.

    Thanks,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Alan Grunwald@nospam.nurdglaw@gmail.com to comp.lang.tcl on Tue May 20 12:55:55 2025
    From Newsgroup: comp.lang.tcl

    On 20/05/2025 09:32, Harald Oehlmann wrote:
    Am 19.05.2025 um 16:05 schrieb Alan Grunwald:
    Tk recognises a lot of colour names, as documented at, say, https://
    www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to get a
    list of them?

    I guess I could hack it out of one of the source files, but I'd hope
    to be able to get it in a cleaner fashion.

    Alan,
    this is a long awaited low hanging fruit in Tk.
    An "tkinfo colornames" should be implemented.

    I would love to use it in colour chooser dropdown boxes etc.

    Thanks,
    Harald
    Thanks Harald,

    That indeed is what I hope to use it for. I'm going to parse rgb.txt as recommended elsewhere. At times like this, I wish I understood the
    Tcl/Tk internals better; I might have a go at implimenting [tkinfo colournames] myself - I'm a Brit, I look forward to the
    colournames/colornames argument :-)

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Alan Grunwald@nospam.nurdglaw@gmail.com to comp.lang.tcl on Tue May 20 12:59:29 2025
    From Newsgroup: comp.lang.tcl

    On 19/05/2025 19:04, Robert Heller wrote:
    Are these colors any different from the X11 colors, listed in /usr/share/X11/rgb.txt ?


    Thanks Robert. I'll have a go at parsing rgb.txt

    Alan
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Olivier@user1108@newsgrouper.org.invalid to comp.lang.tcl on Tue May 20 12:18:18 2025
    From Newsgroup: comp.lang.tcl


    Alan Grunwald <nospam.nurdglaw@gmail.com> posted:

    Tk recognises a lot of colour names, as documented at, say, https://www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to
    get a list of them?

    I guess I could hack it out of one of the source files, but I'd hope to
    be able to get it in a cleaner fashion.

    Most color pickers have a list of them. The most useful is probably this one ( https://wiki.tcl-lang.org/page/Color+pickers ) because of its hexedecimalcorresponding values.

    Olivier.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From greg@gregor.ebbing@gmx.de to comp.lang.tcl on Tue May 20 17:00:07 2025
    From Newsgroup: comp.lang.tcl

    Am 19.05.25 um 16:05 schrieb Alan Grunwald:
    Tk recognises a lot of colour names, as documented at, say, https:// www.tcl-lang.org/man/tcl9.0/TkCmd/colors.html Is it possible to get a
    list of them?

    I guess I could hack it out of one of the source files, but I'd hope to
    be able to get it in a cleaner fashion.


    I need a list of color names.
    Linux Debian:
    /usr/share/X11/rgb.txt
    or
    https://gitlab.freedesktop.org/xorg/app/rgb/raw/master/rgb.txt

    or
    in the demo directory is a file with color name
    file join $::tk_library demos colors.tcl


    Then use winfo to check. https://www.tcl-lang.org/man/tcl8.6/TkCmd/winfo.htm#M30


    }
    package require Tk

    #the proc can only read rgb.txt
    proc readRgbFile {rgbFile} {
    set fh [open $rgbFile r]
    set db {}
    while {[gets $fh line] >= 0} {
    if {[string match {!*} $line]} continue
    set name [lassign $line r g b]
    set hex [format "#%02X%02X%02X" $r $g $b]
    # Use {-1 -1 -1} if in list, or continue if not recognized
    set winfo [expr {[catch {winfo rgb . $name} msg] ? [continue] : $msg}]
    #set winfo [expr {[catch {winfo rgb . $name} msg] ? {-1 -1 -1} : $msg}]
    dict set db $name [dict create r $r g $g b $b hex $hex winfo $winfo]
    }
    close $fh
    return $db
    }
    set namergb [readRgbFile rgb.txt]
    #set namergb [readRgbFile /usr/share/X11/rgb.txt]
    foreach sc {red green lime blue white black yellow "DebianRed"} {
    if {[dict exists $namergb $sc]} {
    puts "searchColor $sc: [dict get $namergb $sc]"
    } else {
    puts "searchColor $sc: Not found"
    }
    }


    # or just a proc for checking
    proc colorExists {color} {
    return [expr {![catch {winfo rgb . $color}]}]
    }



    if {0} {
    #Output:
    ./nn-example.tcl


    searchColor red: r 255 g 0 b 0 hex #FF0000 winfo {65535 0 0}
    searchColor green: r 0 g 255 b 0 hex #00FF00 winfo {0 32896 0}
    searchColor lime: r 0 g 255 b 0 hex #00FF00 winfo {0 65535 0}
    searchColor blue: r 0 g 0 b 255 hex #0000FF winfo {0 0 65535}
    searchColor white: r 255 g 255 b 255 hex #FFFFFF winfo {65535 65535 65535} searchColor black: r 0 g 0 b 0 hex #000000 winfo {0 0 0}
    searchColor yellow: r 255 g 255 b 0 hex #FFFF00 winfo {65535 65535 0} searchColor debianred: Not found


    }
    best regards
    Gregor

    --- Synchronet 3.21a-Linux NewsLink 1.2