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

Possible to combine TK option and value in one variable?

0 views
Skip to first unread message

Helmut Giese

unread,
Aug 29, 2002, 1:43:38 PM8/29/02
to
Hello out there,
when I'm struggling with 'pack' to get my widgets where *I* want, I
often find it useful to give them a (temporary) background color that
makes them "stick out" from the overall appearance of the window (e.g.
-bg gray50).
What I would like to be able to is say something like
set gray50 "-bg gray50"
and use it like
[label -text MyLabel $gray50]

Then (usually much later), after fiddling with 'pack' I would just say
set gray50 ""
and this setting of the background would disappear without me having
to re-edit all widgets where I used it.
Nice idea I thought - it just doesn't work: TK treats all of "-bg
gray50" as *one* option - which it cannot understand of course.

Could someone think of another means to achieve what I would like to?
Any hints will be greatly appreciated.
Helmut

Ken Jones

unread,
Aug 29, 2002, 2:33:04 PM8/29/02
to
"Helmut Giese" <hgi...@ratiosoft.com> wrote in message
news:3d6e59f8...@News.CIS.DFN.DE...

Well, the solution to your original question would be to use [eval], like
this:

################
set gray50 "-bg gray50"
eval {label .l -text "Hello, World!"} $gray50
pack .l
set gray50 ""
eval {label .l2 -text "Hello, again!"} $gray50
pack .l2

################

But in my opinion, a better solution would be to use the option resource
database. You could define some default background colors, foreground
colors, fonts, etc. at the beginning of your application, which would then
be used automatically by widgets that you create afterwards. When you're
finished debugging, simply comment out those settings. For example, you
could set the background color to red for all label widgets subsequently
created with the following command:

option add *Label.background red widgetDefault

If you wanted to apply this "debugging color" only to specific widgets, you
can explicitly name them instead of using the widget class in the [option
add] command. This also allows you to do "spot colors" in addition to your
overall defaults. For example, try this:

################
option add *Label.background red widgetDefault
option add *company.background blue widgetDefault
label .msg -text "The best Tcl training"
label .company -text "Avia Training and Consulting"
pack .msg .company

################

Another handy variation on this technique is to apply the settings only to
specific sections of your layout. For example, we can set the default
background color to blue for all buttons contained within a frame named
".controls" with a command like this:

################
option add *controls.Button.background blue widgetDefault
button .start -text Start
frame .controls
button .controls.ok -text Ok
button .controls.cancel -text Cancel
pack .start
pack .controls -expand yes -fill both
pack .controls.ok .controls.cancel -expand yes -fill x
################

- Ken Jones, President
Avia Training and Consulting
www.avia-training.com
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax

Helmut Giese

unread,
Aug 29, 2002, 2:56:57 PM8/29/02
to
On Thu, 29 Aug 2002 18:33:04 GMT, "Ken Jones" <k...@avia-training.com>
wrote:

>"Helmut Giese" <hgi...@ratiosoft.com> wrote in message
>news:3d6e59f8...@News.CIS.DFN.DE...
>> when I'm struggling with 'pack' to get my widgets where *I* want, I
>> often find it useful to give them a (temporary) background color that
>> makes them "stick out" from the overall appearance of the window (e.g.
>> -bg gray50).
>> What I would like to be able to is say something like
>> set gray50 "-bg gray50"
>> and use it like
>> [label -text MyLabel $gray50]
>>
>> Then (usually much later), after fiddling with 'pack' I would just say
>> set gray50 ""
>> and this setting of the background would disappear without me having
>> to re-edit all widgets where I used it.
>> Nice idea I thought - it just doesn't work: TK treats all of "-bg
>> gray50" as *one* option - which it cannot understand of course.
>>
>> Could someone think of another means to achieve what I would like to?
>> Any hints will be greatly appreciated.
>
>Well, the solution to your original question would be to use [eval], like
>this:

[a simple solution to my problem]

>But in my opinion, a better solution would be to use the option resource

[followed by a tutorial on "How to do this the right way"]

Awesome, Ken. You're the greatest - ok, let's not hurt the others, one
of them few. And extremely helpful.
Thanks an awful lot
Helmut

Gerald W. Lester

unread,
Aug 29, 2002, 3:38:18 PM8/29/02
to

Well, besides the excellent (and correct) solution below. You might
want to consider using grid instead of pack, *most* people find it
easier "to get the widgets where they want them" with grid than with
pack.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is
|
| Gerald...@cox.net | the man who is alive." -- Cervantes
|
+--------------------------------+---------------------------------------+

Helmut Giese

unread,
Aug 29, 2002, 5:06:33 PM8/29/02
to
On Thu, 29 Aug 2002 19:38:18 GMT, "Gerald W. Lester"
<gerald...@cox.net> wrote:

>
>Well, besides the excellent (and correct) solution below. You might
>want to consider using grid instead of pack, *most* people find it
>easier "to get the widgets where they want them" with grid than with
>pack.

That true? Well, I think I'll give it a try on the next project. I
only use 'pack' because it is the first manager I was exposed to, than
spent time getting aquainted with, grasping its concept and learning
it. Not the most convincing reason in the world, but that's just the
way it is.
BTW, where would I find a tutorial on 'grid'?
Thanks for the tip
Helmut

Wojciech Kocjan

unread,
Aug 29, 2002, 6:14:10 PM8/29/02
to

Just try
grid .label0 -row 0 -column 0 -sticky news
grid .label1 -row 1 -column 0 -sticky news
grid .entry0 -row 0 -column 1 -sticky news
grid .entry0 -row 1 -column 1 -sticky news

Also, maybe grid columnconfigure . 1 -weight 1

I also started with pack, it was more intuitive after writing MUI
applications on Amiga :) Right now I can't live w/o grid (although
learning the columnconfigure/rowconfigure -weight took me some time -
don't know why :)

--
WK

Cameron Laird

unread,
Aug 29, 2002, 6:18:05 PM8/29/02
to
In article <3d6e8af...@News.CIS.DFN.DE>,
Helmut Giese <hgi...@ratiosoft.com> wrote:
.
.

.
>BTW, where would I find a tutorial on 'grid'?
.
.
.
<URL: http://www.pconline.com/~erc/grid.htm >, among others.
--

Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html

Helmut Giese

unread,
Aug 30, 2002, 5:40:06 AM8/30/02
to
On Fri, 30 Aug 2002 00:14:10 +0200, Wojciech Kocjan
<wojc...@n0spam-kocjan.org> wrote:
>Right now I can't live w/o grid
Huh, seems to be addictive - maybe I should watch out :)
Thanks
Helmut

Helmut Giese

unread,
Aug 30, 2002, 5:40:39 AM8/30/02
to
On 29 Aug 2002 17:18:05 -0500, cla...@starbase.neosoft.com (Cameron
Laird) wrote:

>In article <3d6e8af...@News.CIS.DFN.DE>,
>Helmut Giese <hgi...@ratiosoft.com> wrote:
> .
> .
> .
>>BTW, where would I find a tutorial on 'grid'?
> .
> .
> .
><URL: http://www.pconline.com/~erc/grid.htm >, among others.

Thanks,
tucked away for later use.
Helmut

Jotux

unread,
Aug 30, 2002, 5:46:42 AM8/30/02
to
> >Well, besides the excellent (and correct) solution below. You might
> >want to consider using grid instead of pack, *most* people find it
> >easier "to get the widgets where they want them" with grid than with
> >pack.

tk has three geometry managers. pack, grid, and place. pack just crams it
in the window. Grid creats a grid and puts it in one of the cells. Place
lets you specify exact x,y position of widget. Try em all, they all have
there own good uses :-)

~Jotux


Donal K. Fellows

unread,
Sep 2, 2002, 5:43:50 AM9/2/02
to
Jotux wrote:
> tk has three geometry managers. pack, grid, and place. pack just crams it
> in the window. Grid creats a grid and puts it in one of the cells. Place
> lets you specify exact x,y position of widget. Try em all, they all have
> there own good uses :-)

Well, not exactly. Firstly, there are a number of widgets which can also act as
window managers (like the [canvas] and [text] widgets.) Secondly, all three of
the "standard" geometry managers do much more than you mention. Thirdly, 8.4
adds new functionality which makes it even easier to do cool stuff. :^)

(GM mastery takes time, in large part because there's so many great things you
can do with them.)

Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal....@man.ac.uk
-- I'm curious; where does this statistic come from? Does its home, perchance,
ever see sunlight? -- Jason A Williams <jason+...@compsoc.man.ac.uk>

Cameron Laird

unread,
Sep 2, 2002, 6:18:26 AM9/2/02
to
In article <3D7332D6...@man.ac.uk>,

Donal K. Fellows <donal.k...@man.ac.uk> wrote:
>Jotux wrote:
>> tk has three geometry managers. pack, grid, and place. pack just crams it
.
.
.

>(GM mastery takes time, in large part because there's so many great things you
>can do with them.)
.
.
.
Yes, and that's true with all GUI toolkits. One of
Tk's long-time attractions has always been that it
has GMs that are easy for newcomers--you can learn
to
pack .mylabel .myentry .mybutton
by rote, and get reasonably satisfying results for
the first few days.

I'm not correcting Donal. Like him, I'm just color-
ing in a bit of pertinent emphasis.

Helmut Giese

unread,
Sep 2, 2002, 8:41:42 AM9/2/02
to
>the "standard" geometry managers do much more than you mention. Thirdly, 8.4
>adds new functionality which makes it even easier to do cool stuff. :^)
As far as doing GUI development is concerned, "bread and butter" stuff
is usually all I need. :) Still, could you point me to a URL where I
could read up on the new features?
Best regards
Helmut

Donal K. Fellows

unread,
Sep 3, 2002, 8:28:15 AM9/3/02
to

Well, you could just wait for the 8.4.0 release which will include a changes
file, but you might want to look at:
http://purl.org/tcl/tip/21
http://purl.org/tcl/tip/37

There's also several TIPs which create new widgets that can contain other
widgets (both [labelframe] and [panedwindow]...)

Helmut Giese

unread,
Sep 3, 2002, 9:06:41 AM9/3/02
to
On Tue, 03 Sep 2002 13:28:15 +0100, "Donal K. Fellows"
<donal.k...@man.ac.uk> wrote:
>Well, you could just wait for the 8.4.0 release which will include a changes
>file, but you might want to look at:
> http://purl.org/tcl/tip/21
> http://purl.org/tcl/tip/37
Looks interesting, especially tip 21 will come in handy, since I'm
often throwing in frames to achieve a certain layout.
Thanks
Helmut
0 new messages