From: 李偉弘 (supershanacon_at_gmail.com)
Date: Wed Jun 10 2020 - 08:16:23 CDT

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 -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 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


gui.png error.png