• Re: Named colours in Tk

    From Ralf Fassel@21:1/5 to All on Mon May 19 17:35:46 2025
    * Alan Grunwald <[email protected]>
    | 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'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ian@21:1/5 to Alan Grunwald on Mon May 19 09:49:11 2025
    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 **************

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Mon May 19 18:04:47 2025
    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 <[email protected]> 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
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ian@21:1/5 to Robert Heller on Mon May 19 17:11:00 2025
    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 <[email protected]> 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 **************

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Alan Grunwald on Mon May 19 19:51:38 2025
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to Robert Heller on Tue May 20 10:03:52 2025
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Tue May 20 10:32:39 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Olivier@21:1/5 to All on Tue May 20 12:18:18 2025
    Alan Grunwald <[email protected]> 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Tue May 20 17:00:07 2025
    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

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