Version 0 of itcl::scope

Updated 2006-12-09 15:07:57

Scope gives a full description of an Itcl variable. Read the manual for details but this code (derived from the manual) may help:

  console show;  update idletasks

  package require Itcl
  itcl::class hellobtn {
   private variable nuses 0
    constructor {frm} {
        puts "IN $this variable nuses is scoped [itcl::scope nuses]"
        pack [ button $frm.nus -textvariable [itcl::scope nuses] -command "$this increm 1" ]
    }
  method increm {dn} { incr nuses $dn }
  }
  foreach ibtn {1 2 3 4} {
          pack [frame .f$ibtn];   hellobtn  h$ibtn .f$ibtn
  }

the output from the constructor is:

  IN ::h1 variable nuses is scoped @itcl ::h1 ::hellobtn::nuses

thus scope nuses has returned "@itcl ::h1 ::hellobtn::nuses" - or

  • we are in itcl, (@itcl appears to be a constant)
  • the itcl object's global name is ::h1
  • the full name of the variable is ::hellobtn::nuses

In the next line, the text variable displayed on the button is a private variable (ie not a global as usually used by Tk) so multiple instances of hellobtn could use different the same variable name but with the scope the variable becomes unique. the example creates 4 buttons using the same itcl class, all use the same internal variable name but each button increments its value independently of the other buttons.