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

Showing a variable from a TclOO object in a Tk widget?

112 views
Skip to first unread message

Arjen Markus

unread,
Feb 9, 2018, 3:00:42 AM2/9/18
to
Hello,

I tried to display a variable from a TclOO object in a button, like:

method show {} {
variable mytext

set mytext "Some text"

pack [button .b -textvariable mytext]
}

(and several other forms) but it does not work. Obviously "mytext" need to acces the actual variable from the global context, but I would like to know how to achieve this in this set-up.

Regards,

Arjen

kearnh

unread,
Feb 9, 2018, 3:32:55 AM2/9/18
to
does "pack [button .b -textvariable [my varname mytext]" work?

Arjen Markus

unread,
Feb 9, 2018, 4:02:22 AM2/9/18
to
On Friday, February 9, 2018 at 9:32:55 AM UTC+1, kearnh wrote:
> does "pack [button .b -textvariable [my varname mytext]" work?

I tried that variant, but it did not have the effect I am looking for.

Regards,

Arjen

Arjen Markus

unread,
Feb 9, 2018, 5:49:15 AM2/9/18
to
I also tried:

method link {varname} {
variable mytext
upvar #0 $varname mytext
}

and then invoking the link method in the global namespace

This did not work either. Neither with [my variable mytext]

Regards,

Arjen

Schelte Bron

unread,
Feb 9, 2018, 7:02:53 AM2/9/18
to
Arjen Markus wrote:
> This did not work either. Neither with [my variable mytext]
>
How about [button .b -textvariable [namespace which -variable
mytext]]?


Schelte.

Arjen Markus

unread,
Feb 9, 2018, 7:16:23 AM2/9/18
to
Ah, wonderful! That works indeed!

Regards,

Arjen

Bezoar

unread,
Feb 10, 2018, 10:23:01 AM2/10/18
to
this works too:

button .b -textvariable [self]::mytext

Donal K. Fellows

unread,
Feb 10, 2018, 12:12:09 PM2/10/18
to
On 09/02/2018 09:02, Arjen Markus wrote:
> I tried that variant, but it did not have the effect I am looking for.

That's funny, since it is *supposed* to work…

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

Brad Lanam

unread,
Feb 10, 2018, 2:07:53 PM2/10/18
to
'my varname' works for me.
I use 'my variable' rather than 'variable' in my classes.

Matthew Hiles

unread,
Feb 16, 2018, 9:34:40 AM2/16/18
to
Keep in mind, all the awesomeness that is TclOO was done using existing Tcl mechanisms. Each object has its own namespace that is globally addressable just like a regular variable or proc in a namespace.

Arjen Markus

unread,
Feb 16, 2018, 9:40:59 AM2/16/18
to
Sure, that is why I was surprised tjos

Arjen Markus

unread,
Feb 16, 2018, 9:47:23 AM2/16/18
to
On Friday, February 16, 2018 at 3:40:59 PM UTC+1, Arjen Markus wrote:
> Sure, that is why I was surprised tjos

Uh, surprised to see this go wrong, I means.

Perhaps I should check again, but I do have a workaround now.

Regards,

Arjen

Christian Gollwitzer

unread,
Feb 16, 2018, 2:27:09 PM2/16/18
to
Am 09.02.18 um 09:00 schrieb Arjen Markus:
> I tried to display a variable from a TclOO object in a button, like:
>
> method show {} {
> variable mytext
>
> set mytext "Some text"
>
> pack [button .b -textvariable mytext]
> }

I suggest you take a look at a "real" megawidget framework. So far,
there is no blessed "TkOO" in existence, but the "snot" port comes close:

http://chiselapp.com/user/aspect/repository/snot/index

In snot, [my variable mytext] is supposed to work. If it doesn't than
that's a bug which should be fixed. In addition snot also does all the
other stuff like renaming the original widget command and binding the
destruction sequence etc.

Christian
0 new messages