Menu

#173 -namespace option for "bind" and widgets

open
5
2005-09-24
2005-09-24
Anonymous
No

pass namespace name for script execution.
Sample :
button .b -namespace [ namespace current ] -command {
set flag "clicked"
}
bind .b <FocusIn> -namespace ::other {
set focusOwner %W
}

This solution maid tk script simple and more readable,
prevent global`ization. Also gain help for tk extensions.

Discussion

  • Don Porter

    Don Porter - 2005-09-26

    Logged In: YES
    user_id=80530

    The traditional solution here, of course,
    is to use [namespace code]:

    Hmmm... tried to give an example
    corresponding to yours, and I realize
    I don't understand yours.

    Care to spell things out in more detail?

     
  • Nobody/Anonymous

    Logged In: NO

    sample - need pass value as arguments to proc
    ### current version ###
    set data "pass there"
    # next line true, but long and hard readable
    button .b -command [ list [namespace current]::anyproc $data ]
    bind .b <FocusIn> [ namespace code {
    # next line wrong - variable `data` already changed or
    unset`ted
    anotherproc $data
    } ]
    ### with -namespace option ###
    button .b -namespace [namespace current]
    .b configure -command [list anyproc $data]
    .b bind <FocusIn> [list anotherproc $data ]

    Code has been more readable,
    bindings and commands scripts don`t
    contain namespace names and may easy exported and reused.

    This solution also open way to easy port old applications to
    newest namespace model with minimal code changes.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.