From: yjcoshc (yjcoshc_at_gmail.com)
Date: Wed Jun 10 2020 - 17:08:56 CDT

You may intend to use "variable w" instead of "set variable w". The
former means creating a variable named "w" in the namespace ::myscript,
but the latter means declaring a variable named "variable" and assigning
the string "w" to it.

在 2020/6/10 上午8:16, 李偉弘 写道:
> Hi everyone,I'm trying to make a plugin which can input the parameters
> and save file.
> There's some "label" "entry" and a start "buttom".After I input the
> parameters and press the start button,error happened(error said can't
> read "w". no such variable.).
> I use the vmd_install_extension command to install my script
> package.Reading this
> reference(https://www.tutorialspoint.com/tcl-tk/tcl_packages.htm) to
> build the package.
> Please give me some suggestions,thank you.
>
> here's my code:
> # Create the namespace
> namespace eval ::myscript {
>
>   # Export MyProcedure
>
>   namespace export myscript_gui
>
>   # My Variables
>    set version 1.1
>    set MyDescription "myscript"
>
>
>    set variable w
>    set variable filename
>    set variable a
>    set variable b
>    set variable c
>
>   # Variable for the path of the script
>    variable home [file join [pwd] [file dirname [info script]]]
>
> }
>
> proc ::myscript::myscript_gui {} {
>    set variable w
>    set variable filename
>    set variable a
>    set variable b
>    set variable c
>
>
>
>    set w [toplevel ".myscriptgui"]
>    wm title $w "myscript"
>
>    frame $w.input
>
>
>    grid [label $w.input.withinlabel -text "input within "] \
>     -row 1 -column 0 -sticky w
>    grid [entry $w.input.within -width 20 -textvariable ::myscript::a]\
>     -row 1 -column 1 -sticky ew
>
>    grid [label $w.input.residlabel -text "input resid "] \
>     -row 2 -column 0 -sticky w
>    grid [entry $w.input.resid -width 20 -textvariable ::myscript::b]\
>     -row 2 -column 1 -sticky ew
>
>    grid [label $w.input.namelabel -text "which atom (name) "] \
>     -row 3 -column 0 -sticky w
>    grid [entry $w.input.name <http://w.input.name> -width 20
> -textvariable ::myscript::c]\
>     -row 3 -column 1 -sticky ew
>
>    grid [label $w.input.openfilelabel -text "savefile name"] \
>     -row 4 -column 0 -sticky w
>    grid [entry $w.input.openfile -width 20 -textvariable
> ::myscript::filename]\
>     -row 4 -column 1 -sticky ew
>
>
>  grid [button $w.input.start -text "start" \
>     -command {
>         set a [$w.input.within get]
>         set b [$w.input.resid get]
>         set c [$w.input.name <http://w.input.name> get]
>         set filename [$w.input.openfile get]
>         set file [open "$filename .dat" w]
>
>         set sel [atomselect top "{within $a of {resid $b and name $c}}
> and {not resname TIP3 POPC} and {not resid $b}"]
>         for {set i 1} {$i <= 999} {incr i 1} {
>             $sel frame $i
>             $sel update
>             puts $file "frame[$sel frame] [$sel get {name index}]"
>                                              }
>
>
>
>     }] -row 5 -column 0 -sticky w
>
>    pack $w.input
>
> }
>
>
>
> proc myscript_tk {} {
>   myscript::myscript_gui
>   return $myscript::w
> }
>
> package provide myscript $myscript::version
> package require Tcl 8.5.6