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

ISO: ways to figure out a widget type

5 views
Skip to first unread message

Larry W. Virden

unread,
Aug 16, 2005, 8:04:18 AM8/16/05
to
Someone I know is writing some tcl code that needs to know what kind of
a widget a particular widget is . That is to say, if the path .t.p1.s2
were passed, he needs to figure out what code is needed to determine
whether the widget is a slider, or a button, or a label, etc.

Arjen Markus

unread,
Aug 16, 2005, 8:08:33 AM8/16/05
to
Use the [winfo class] command:

button .b
winfo class .b
==> Button

Regards,

Arjen

Ralf Fassel

unread,
Aug 16, 2005, 8:07:57 AM8/16/05
to
* "Larry W. Virden" <lvi...@gmail.com>

| That is to say, if the path .t.p1.s2 were passed, he needs to figure
| out what code is needed to determine whether the widget is a slider,
| or a button, or a label, etc.

% label .w
% winfo class .w
=> Label

R'

Joe English

unread,
Aug 16, 2005, 12:26:53 PM8/16/05
to

Depending on what it is he's trying to do, he might be
better off using virtual events and class bindings, e.g.,:

bind Button <<DoSomething>> { ... code for button widgets ... }
bind Label <<DoSomething>> { ... code for label widgets ... }
...
event generate .t.p1.s2 <<DoSomething>>


Without knowing the details of the problem in question it's
hard to say whether this approach is appropriate or not;
but personally I've always found this technique to be far
superior to switching on [winfo class $w].


--Joe English

Ralf Fassel

unread,
Aug 18, 2005, 4:36:25 AM8/18/05
to
* jeng...@flightlab.com (Joe English)

| Depending on what it is he's trying to do, he might be
| better off using virtual events and class bindings, e.g.,:
|
| bind Button <<DoSomething>> { ... code for button widgets ... }
| bind Label <<DoSomething>> { ... code for label widgets ... }
| ...
| event generate .t.p1.s2 <<DoSomething>>

Nice one.
R'

0 new messages