Hi, I just started to learn tcl and TclOO, so i need some help with my class. I want to run method Print for my object, when i press button, how can i do it?
Here is example
package require Tk
oo::class create test {
constructor {} {
my gui
}
method gui {} {
pack [frame .main -bg green] -fill both -padx 2 -pady 2 -expand yes -side left -anchor ne
pack [button .b -text "test" -relief flat -command [??????????]] -side left -padx 2 -pady 2
}
method Print {} {
puts "ola"
}
}
set c [test new]I can do it like this, but in this case method print is public:
package require Tk
oo::class create test {
constructor {} {
my gui
}
method gui {} {
pack [frame .main -bg green] -fill both -padx 2 -pady 2 -expand yes -side left -anchor ne
pack [button .b -text "test" -relief flat -command "[self] print"] -side left -padx 2 -pady 2
}
method print {} {
puts "ola"
}
}
set c [test new]Thank you
Try something like:
[namespace code { my Print }]DKF: The my command is always in the object's current namespace (strictly, there's one per object) so you can use:
[list [namespace current]::my Print]
Alternatively, you can either use the namespace code call above. Or build a command with namespace eval:
[list namespace eval [namespace current] [list my Print]]
You can use “info object namespace [self]” instead of “namespace current”, but that's a bit long-winded. (The name of an object's namespace is not documented, but it is an almost entirely ordinary namespace but with an object hanging off it and with a lot of tuning applied.)