View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] NX direct variable access

From: Gustaf Neumann <>
Date: Wed, 19 Jan 2011 13:50:25 +0100

Am 19.01.11 10:19, schrieb Victor Mayevski:
> In NX, what is the correct way to give a direct access to an object
> variable for outside caller, just like we used to do with XOTcl's
> [myvar varname]?
I assume, you want to obtain a fully qualified variable handle for an
instance variable. Essentially, it works in nx very similar to XOTcl.
See below for the method "bindvar" which obtains the fully
qualified name and shows its usage in the context of Tk.

-gustaf neumann

# Tiny Tk example with bindvar and callback
# -gustaf neumann

package require nx
package require Tk

nx::Class create Callbacks {
   # A small support class to ease syntactically the reference to
   # instance variables and the registration of callbacks.
   :method bindvar {name} {
     :require namespace
     return [nx::self]::$name
   :method callback {name args} {
     return [list [nx::self] $name {*}$args]

nx::Class create Myclass {

   # A sample application class that creates a text entry field bound
   # to an instance variable. When the provided button is pressed, the
   # content of the variable is placed into an additional output label.

   :mixin Callbacks

   :public method button-pressed {} {
     .label configure -text ${:myvar}

   :method init {} {
     wm geometry . -500+500
     pack [label .title -text "Type something and press start button...."]
     pack [entry .text -textvariable [:bindvar myvar]]
     pack [label .label]
     pack [button .button -text start -command [:callback button-pressed]]

Myclass new

Univ.Prof. Dr. Gustaf Neumann
Institute of Information Systems and New Media
WU Vienna
Augasse 2-6, A-1090 Vienna, AUSTRIA