configure cget tcl tk

    class Person {
        public variable name ""
        public variable phone ""
        public variable email ""

        constructor {args} {
            eval configure $args
        }
    }

This class has three public attributes: the person's name, phone number and e-mail address. Any extra args passed to the constructor are treated as configuration options and passed along to configure. A Person object can be created like this:

    Person bob -name "Cyber Bob" \
        -phone "555-4bob" \
        -email "cbob@foo.com"

and reconfigured like this:

    bob configure
     => {-email {} cbob@foo.com} {-name {} {Cyber Bob}} {-phone {} 555-4bob}

    bob configure -phone
     => -phone {} 555-4bob

    bob configure -phone 1-800-num-4bob
     =>

    bob cget -phone
     => 1-800-num-4bob

posted @ 2011-04-24 20:44  greencolor  阅读(313)  评论(0编辑  收藏  举报