From: kk on
Hi all,

A newbie to tcl/tk, but really excited about the elegance of the
prefix notation. :)
Question: Is there anyway to do what is known as subclassing in MFC
terminology?

For example

if we have
button .b -text "mybutton" -command { puts "Hello there" }

I can refer to the above specific button as .b. But can I put multiple
instances of the above .b button in the same geometry manager? I
should not have any problem putting them in different geometry
managers right? Can the code inside the -command find out the calling
widget hierarchy?

And is that the only soln? Namely wrap each button in a different
manager before placing all the managers on the screen/widget
From: Pat Thoyts on
kk <girishbhat6620(a)gmail.com> writes:

>Hi all,
>
>A newbie to tcl/tk, but really excited about the elegance of the
>prefix notation. :)
>Question: Is there anyway to do what is known as subclassing in MFC
>terminology?
>
>For example
>
>if we have
>button .b -text "mybutton" -command { puts "Hello there" }
>
>I can refer to the above specific button as .b. But can I put multiple
>instances of the above .b button in the same geometry manager? I
>should not have any problem putting them in different geometry
>managers right? Can the code inside the -command find out the calling
>widget hierarchy?
>
>And is that the only soln? Namely wrap each button in a different
>manager before placing all the managers on the screen/widget

..b is an instance of a button class. You can apply some appearance
modifications via te -class option and the option database but its
probably not what you are thinking of.

Subclassing the way you refer to it would be making a new command that
creates a widget that is related but not identical to a button. For
instance a togglebutton. When you might say [togglebutton .tb -text
"click"] and get something that remembers it is pressed or non-pressed.

The BWidgets library is one way to make these. tklib might have some
others. Basically you implement a widget creation command to create
widget instances.

the info and winfo commands introspect tcl and tk variables and widgets
eg: winfo children $widget, winfo parent $self etc.

--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
From: Arndt Roger Schneider on
kk schrieb:

>Hi all,
>
>A newbie to tcl/tk, but really excited about the elegance of the
>prefix notation. :)
>Question: Is there anyway to do what is known as subclassing in MFC
>terminology?
>
>
>

No! As the other postings mentioned, you don't need subclassing in
tcl/tk.

>For example
>
>if we have
>button .b -text "mybutton" -command { puts "Hello there" }
>
>I can refer to the above specific button as .b. But can I put multiple
>instances of the above .b button in the same geometry manager? I
>should not have any problem putting them in different geometry
>managers right? Can the code inside the -command find out the calling
>widget hierarchy?
>
>
>
1) There are some windows, which have a clone command:
text and menu. In theory you could do this with such a clone.

2) More general .b is an object and not a class.
..b is a unique identifier for a tk window.
If you want sibling buttons, each must have a unqiue name:

button .b1 ...
button .b2 ...

3) Yes, no problem the window name is determined by the
path and name. It does not have anything to do with
the geometry manager, this is determined by the parent / child
relationship:

button .b
frame .f
button .f.b

pack .b -in .f
pack .f.b


is allowed because there is only one child b of frame f.


4) No it cannot (It should).
Common practice is to use a list construct as the command

button .b -command [list calledby .b]




>And is that the only soln? Namely wrap each button in a different
>manager before placing all the managers on the screen/widget
>
>
?

-roger