Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk color names available on the script level?

94 views
Skip to first unread message

skuh...@web.de

unread,
Aug 20, 2007, 8:38:53 AM8/20/07
to
Hello

I'm searching for a method to get the color names known to Tk in a
script. I read the wiki and the man pages, but there seems to be no
way. I know, there is a list in man colors, but I don't want the names
hardcoded in the source. Is this possible or no way?

TIA
Stephan

Uwe Klein

unread,
Aug 20, 2007, 8:55:48 AM8/20/07
to
afair:
On unix systems the names are in "rgb.txt" ( and part of the X-Server environment)

uwe

skuh...@web.de

unread,
Aug 20, 2007, 9:10:07 AM8/20/07
to

Uwe Klein wrote:
> afair:
> On unix systems the names are in "rgb.txt" ( and part of the X-Server environment)

I know that, but I need it OS independent (better: Window System
independent)...

Regards
Stephan

Mark Janssen

unread,
Aug 20, 2007, 9:14:31 AM8/20/07
to

Adding named colors is subject of TIP 154 http://www.tcl.tk/cgi-bin/tct/tip/154.html
which is currently in draft state. If you really need this
functionality now and don't mind patching Tk, you can have a look at:
http://sourceforge.net/tracker/index.php?func=detail&aid=1637923&group_id=12997&atid=312997
which includes a patch to add the [wm colors] subcommand.

Mark

skuh...@web.de

unread,
Aug 20, 2007, 9:23:21 AM8/20/07
to

Mark Janssen wrote:
> Adding named colors is subject of TIP 154 http://www.tcl.tk/cgi-bin/tct/tip/154.html
> which is currently in draft state. If you really need this
> functionality now and don't mind patching Tk, you can have a look at:
> http://sourceforge.net/tracker/index.php?func=detail&aid=1637923&group_id=12997&atid=312997
> which includes a patch to add the [wm colors] subcommand.

Thanks for the links, I wasn't aware of the TIP. Patching Tk is not
option, so I think, I skip named colors for the next few years until
8.6 is available... ;-)

Thanks
Stephan

suchenwi

unread,
Aug 20, 2007, 11:09:30 AM8/20/07
to
As a quick fix, you can also borrow (copy/paste) the color names
emulation from http://wiki.tcl.tk/16166 "Colors with Names"


Pascal

unread,
Aug 20, 2007, 11:48:12 AM8/20/07
to
Sorry if I did not get what you're asking for, but I remember that there
is some demo files coming with Tcl (at least on Linux), and one is named
tcolor.tcl (if I remember well).
Maybe you'll get something from that (there is a selection widget
displaying color names).

Pascal

skuh...@web.de a écrit :

Stephan Kuhagen

unread,
Aug 20, 2007, 12:02:17 PM8/20/07
to
suchenwi wrote:

> As a quick fix, you can also borrow (copy/paste) the color names
> emulation from http://wiki.tcl.tk/16166 "Colors with Names"

Thanks, but as I said, I don't want the color names hardcoded into the
source. I found this and some other sources with all color names in the
wiki and of course you need only three lines of Tcl to extract them from
the man page, but it's simply not what I want...

Regards
Stephan

Mark Janssen

unread,
Aug 20, 2007, 12:09:43 PM8/20/07
to
On 20 aug, 18:02, Stephan Kuhagen <skuha...@web.de> wrote:
> suchenwi wrote:
> > As a quick fix, you can also borrow (copy/paste) the color names
> > emulation fromhttp://wiki.tcl.tk/16166"Colors with Names"

>
> Thanks, but as I said, I don't want the color names hardcoded into the
> source. I found this and some other sources with all color names in the
> wiki and of course you need only three lines of Tcl to extract them from
> the man page, but it's simply not what I want...
>
> Regards
> Stephan

Maybe a small C extension would be able to pry the color names from
Tk. Would that be an option?

Mark

Larry W. Virden

unread,
Aug 20, 2007, 12:40:26 PM8/20/07
to

This is one of the areas of introspection still unavailable (another
is cursor names and perhaps built-in image names?).

It would be great if someone created a TIP (http://wiki.tcl.tk/TIP)
and worked on providing these things. It would be much better to have
something within the core that somehow dynamically obtained the valid
information, rather than having things hard coded in some script
library.

Mark Janssen

unread,
Aug 20, 2007, 1:24:48 PM8/20/07
to

The TIP is already there (TIP 154), I guess what is missing is a
complete implementation.

Mark

Mark Janssen

unread,
Aug 20, 2007, 1:44:46 PM8/20/07
to

To make it more explicit. The Tk colors are stored in a hash. The keys
of this hash are the color names. By traversing all hash elements a
colorname list can be constructed. Only doubt I have is whether it
requires inclusion of tkInt.h.
So would a C-extension be OK?

Mark

Stephan Kuhagen

unread,
Aug 20, 2007, 1:49:37 PM8/20/07
to
Mark Janssen wrote:

> Maybe a small C extension would be able to pry the color names from
> Tk. Would that be an option?

No, the script should run on a basic Tcl/Tk 8.4 or newer without any
extensions and on different plattforms (at least Linux (x86 and PPC),
MacOSX (x86, PPC) and on an embedded device with an arm compatible CPU -
and if possible on many others, but thats all I have... So compiling all
those scripts would be too much for a little gimmick.

I'm sorry to make such a noise here, since the feature is not a must have
for my script, so I can live without it. But I agree with Larry and find it
a little bit surprising, that, considering Tcl/Tk other impressive
introspection features, such basic things are not there.

Regards
Stephan

Stephan Kuhagen

unread,
Aug 20, 2007, 1:57:53 PM8/20/07
to
Mark Janssen wrote:

> To make it more explicit. The Tk colors are stored in a hash. The keys
> of this hash are the color names. By traversing all hash elements a
> colorname list can be constructed. Only doubt I have is whether it
> requires inclusion of tkInt.h.
> So would a C-extension be OK?

No, sorry, because of the reasons I just posted. If it were that important,
extracting the colors from the man page or rgb.txt (on X11) would the my
choice. A C extension is overkill for a simple script which should run on
many plattforms and where the feature is not important.

Regards
Stephan

Larry W. Virden

unread,
Aug 21, 2007, 8:55:57 AM8/21/07
to

> > It would be great if someone created a TIP (http://wiki.tcl.tk/TIP)
> > and worked on providing these things. It would be much better to have
> > something within the core that somehow dynamically obtained the valid
> > information, rather than having things hard coded in some script
> > library.
>
> The TIP is already there (TIP 154), I guess what is missing is a
> complete implementation.

Well, TIP 154 goes way beyond what the OP requested, but it could be
used to implement the specific request.

Unless I misunderstood, what the OP wanted was something like:

set colorlist [info colors]

{red white blue black green yellow}

etc.

TIP 154's color names could certainly return that kind of thing, but
it looks, to me, like the TIP is oriented towards returning things
like
{TkButtonFace TkButtonText}
etc. - generic names that represent whatever color a button's face or
text might have.

If in addition to this, TIP 154's color names also returned all the
regular "colors" (either created or pre-set), then that would meet the
OP need.

Jeff Hobbs

unread,
Aug 21, 2007, 7:00:47 PM8/21/07
to Larry W. Virden
Larry W. Virden wrote:
> TIP 154's color names could certainly return that kind of thing, but
> it looks, to me, like the TIP is oriented towards returning things
> like
> {TkButtonFace TkButtonText}
> etc. - generic names that represent whatever color a button's face or
> text might have.
>
> If in addition to this, TIP 154's color names also returned all the
> regular "colors" (either created or pre-set), then that would meet the
> OP need.

I would tend to resist having it return all the color names, unless we
include them all as redefinable colors. There basically is no value in
using those names, except in some demo script.

Jeff

Larry W. Virden

unread,
Aug 22, 2007, 7:49:47 AM8/22/07
to
On Aug 20, 8:38 am, skuha...@web.de wrote:

> I'm searching for a method to get the color names known to Tk

Can you describe how you are planning to use this? For instance, on
Unix, one might have 800+ colors. How would you make use of a huge
list of colors?

skuh...@web.de

unread,
Aug 22, 2007, 8:36:06 AM8/22/07
to

It's for finding the nearest predefined color for a given RGB-Value
and the other way around. Not really important, as I wrote earlier,
just a gimmick for a small script, that I'm writing just for fun. But
getting the predefined color names from Tk would be a useful and
obvious feature. I even would expect the possibilty to extend the
database of named colors...

Regards
Stephan

Joe English

unread,
Aug 22, 2007, 11:40:15 AM8/22/07
to
skuhagen wrote:

>Uwe Klein wrote:
>> On unix systems the names are in "rgb.txt" ( and part of the X-Server
>> environment)
>
>I know that, but I need it OS independent (better: Window System
>independent)...


Ain't no such thing.

If you're looking for "A list of named colors that are
likely to work in Tk on all platforms", then the list
in colors(3Tk) is your best bet.

If you're looking for "A list of named colors that are
likely to work _and look the same_ when used in Tk on
all platforms", then don't bother: you'll get less variation
with explicit #RRGGBB specifications than you will with
named colors. (Colors specified as #RRGGBB won't look the
same on all platforms, but neither will named colors, and
the latter can be significantly different from server
to server.)

If you're looking for something else, then I don't know --
what do you need this for?


--Joe English

Stephan Kuhagen

unread,
Aug 22, 2007, 1:27:48 PM8/22/07
to
Joe English wrote:

> Ain't no such thing.

I know. I just wanted to make sure, that I haven't missed something in the
documentation.

> If you're looking for something else, then I don't know --
> what do you need this for?

It's just a gimmick for a very small fun project, nothing essential for
anything. I quote myself:

Paul@Tcl3D

unread,
Aug 22, 2007, 3:59:39 PM8/22/07
to

Joe English wrote:
> skuhagen wrote:
>> Uwe Klein wrote:
>>> On unix systems the names are in "rgb.txt" ( and part of the X-Server
>>> environment)
>> I know that, but I need it OS independent (better: Window System
>> independent)...
>
>
> Ain't no such thing.
>
> If you're looking for "A list of named colors that are
> likely to work in Tk on all platforms", then the list
> in colors(3Tk) is your best bet.
>

This list of color names and associated rgb values can be found as a Tcl
list (and some utility functions) in the Tcl3D source distribution
(www.tcl3d.org, file tcl3dColors.tcl).

Might be a starting point for your needs.

Paul

0 new messages