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

Button name in his command

1 view
Skip to first unread message

Jeannot

unread,
Jan 5, 2006, 4:36:34 AM1/5/06
to
Hi all,

I was wondering if it is possible to get button name within is command:
set Button .b
button $Button -command {
do another thing ...
$Button configure ...
}

I mean I know that by global I can get it but I was looking for another way.

Thanks a lot

Jeannot

Uwe Klein

unread,
Jan 5, 2006, 4:47:35 AM1/5/06
to

%W configure ...
}


look into "man n bind"
go down to
"BINDING SCRIPTS AND SUBSTITUTIONS"

uwe

Jeannot

unread,
Jan 5, 2006, 4:57:12 AM1/5/06
to
Uwe Klein a écrit :
Thanks ... it is so simple when you know where it is hided !!! :-)

Jeannot

Uwe Klein

unread,
Jan 5, 2006, 5:16:36 AM1/5/06
to
Jeannot wrote:

> Thanks ... it is so simple when you know where it is hided !!! :-)

There are ways beyond drinking the bath-water to get at the soap.
I've had my share of bath-water ;-)
>
> Jeannot
uwe

Donal K. Fellows

unread,
Jan 5, 2006, 6:55:40 AM1/5/06
to
Jeannot wrote:
> I was wondering if it is possible to get button name within is command:
> set Button .b
> button $Button -command {
> do another thing ...
> $Button configure ...
> }

If this was a binding script, you'd be able to use the %W substitution
for this purpose. But no substitutions are performed on button -command
options. Instead, the right approach involves using a helper procedure
and the [list] command:

proc ButtonHelper {Button} {


do another thing ...
$Button configure ...
}

button $Button -command [list ButtonHelper $Button]

Note that the [list] command is used here because it "does exactly the
right thing" in all cases; double-quoting works too, but only for some
values (numbers and conventional widget names included, but arbitrary
strings definitely not!) Using it always is considered Good Practice, as
is putting anything non-trivial like this in a helper procedure anyway.

Donal.

Uwe Klein

unread,
Jan 5, 2006, 7:05:45 AM1/5/06
to
OK, more bath-water to me

uwe

Bryan Oakley

unread,
Jan 5, 2006, 7:12:09 AM1/5/06
to
Uwe Klein wrote:

>
> button $Button -command {
> do another thing ...
> %W configure ...
> }
>
>
> look into "man n bind"
> go down to
> "BINDING SCRIPTS AND SUBSTITUTIONS"

"bind" and "-command" are two different things. What you suggest won't work.

As a rule of thumb, never have more than one command inside a -command
or binding. Rule of thumb two, use [list] to create that command:

button $Button -command [list doSomething $Button]
proc doSomething {w} {
puts "I was called by $w"
}

Jeannot

unread,
Jan 5, 2006, 7:57:03 AM1/5/06
to
Bryan Oakley a écrit :

You are right ... I thought too quickly it works. I will check the other
solution.

Jeannot

Jeannot

unread,
Jan 5, 2006, 8:06:11 AM1/5/06
to
Uwe Klein a écrit :
Same for me :-)

good day for learning

thanks

Jeannot

0 new messages