Re: How to set ttk::radiobutton -variable to an object's instance variable?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: How to set ttk::radiobutton -variable to an object's instance variable?
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 12. Jul 2025, 01:28:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104sa6r$1p3q4$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 7/11/2025 4:13 PM, Emiliano wrote:
On Fri, 11 Jul 2025 21:12:08 +0200
Schelte <nospam@wanadoo.nl> wrote:
 ...
Another way to get the fully qualified name of the variable is
[namespace which -variable ShowState]. But as that produces the same
result, it also won't work until you fix that other bug.
 Adding to what Schelte correctly pointed out, these are your options:
 * [my varname somevar]: This works inside TclOO objects, and works for scalar
   variables, arrays and array elements.
* [namespace which -variable somevar]: This works inside TclOO objects and
   namespaces. Works for scalar variables and arrays, but not for array
   elements. See Tcl bug#472113 . If you need an array element, use
   [namespace which -variable somearray](element).
* last but not least, [namespace current]::somevar works if somevar is
   a variable in the current namespace, including the namespace of any TclOO
   object, and works for scalar, array and array elements.
 Regards
As a learning exercise,
I filled in Mark's code (added the 2 frames, a second radio button, and packed it up) and used the [my varname ...] form which worked for me.
Here's a little debug procedure one can use to find object variables. It might prove helpful. Note, the [my varname ...] will register the variable in the object's namespace, but the variable is still unset, which this code can show.
#   Function to dump all object variables
     proc dovar {{all 0} {sep "-----------------------------------"} } {
         if { $sep ne "" } {
             puts $sep
         }
         foreach ns [namespace children ::oo] {
             if {[string match "Obj*" [namespace tail $ns]]} {
                 set objName ::$ns
                 set class "<unknown>"
                 catch {
                     set class [info object class $objName]
                 }
                 if {!$all && $class eq "<unknown>"} {
                     continue
                 }
                 puts "Object: $objName (Class: $class)"
                 foreach var [info vars ${ns}::*] {
                     set shortName [namespace tail $var]
                     if {[info exists $var]} {
                         catch { set val [set $var] }
                     } else {
                         set val "<unset>"
                     }
                     puts "  $shortName ($var) = $val"
                 }
             }
         }
         if { $sep ne "" } {
             puts $sep
         }
     }
-eric

Date Sujet#  Auteur
11 Jul 25 * How to set ttk::radiobutton -variable to an object's instance variable?6Mark Summerfield
11 Jul 25 +- Re: How to set ttk::radiobutton -variable to an object's instance? variable?1Robert Heller
11 Jul 25 `* Re: How to set ttk::radiobutton -variable to an object's instance variable?4Mark Summerfield
12 Jul 25  +* Re: How to set ttk::radiobutton -variable to an object's instance variable?2Emiliano
12 Jul 25  i`- Re: How to set ttk::radiobutton -variable to an object's instance variable?1et99
14 Jul 25  `- Re: How to set ttk::radiobutton -variable to an object's instance variable?1Mark Summerfield

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal