tcl - linking procedure to button -
i have created same user interface using gui builder tcl. however, became limited in terms of how structure interface , spacing between widgets. i've created interface i'm looking create procedure block specific widget. example, quit button exit program.
to achieve created following procedure:
proc btnquit args { exit }
this doesn't cause syntax or runtime error however, when button pressed, program not exit. simplest case there others more complex -command flag not apply situations.
thoughts?
below entire code. bringing user interface.
#includes necessary packages package require bwidget package require tk namespace eval main_menu {} #do not modify!! graphical user interface code not modify!! #limit size of window wm maxsize . 475 180 ;#x-500, y-210 wm minsize . 475 180 ;#x-500, y-210 #[device name] test frame w/ associated check boxes labelframe .lblfrmselection -text "testable devices" -padx 1 -relief groove -height 175 -width 200 button .btndualuta -text "dual uta" -padx 5 -anchor "center" -justify "center" -padx 3 button .btntprobe -text "t-probe" -padx 5 -anchor "center" -justify "center" -padx 7 button .btnoctal -text "octal" -padx 5 -anchor "center" -justify "center" -padx 14 button .btnuniversal -text "universal" -padx 5 -anchor "center" -justify "center" button .btnquit -text "exit" -padx 5 -anchor "center" -justify "center" -padx 18 #setup second frame image label labelframe .lblfrmhwsetup -text "hardware setup" -padx 1 -relief groove -height 200 -width 175 image create photo glcomm.gif label .lblsetup -text "image goes here" #*************** render user environment ****************** #create device test interface check boxes in frame. place .lblfrmselection -anchor nw -x 5 -y 1 -width 165 -height 175 place .btndualuta -in .lblfrmselection -x 40 -y 15 -anchor "w" place .btntprobe -in .lblfrmselection -x 40 -y 46 -anchor "w" place .btnoctal -in .lblfrmselection -x 40 -y 76 -anchor "w" place .btnuniversal -in .lblfrmselection -x 40 -y 106 -anchor "w" place .btnquit -in .lblfrmselection -x 40 -y 136 -anchor "w" #create label frame "hardware setup" place .lblfrmhwsetup -anchor nw -x 170 -y 1 -height 175 -width 300 place .lblsetup -in .lblfrmhwsetup -x 171 -y 2 # modify below line!! modify below line!! proc btnquit args { exit }
you haven't shown how button created, -command
option is need
$ tclsh <<'end' package req tk proc btnquit args {exit} button .b -text quit -command btnquit pack .b end
if button created, can configure -command option
button .b -text quit .b configure -command btnquit
note looks "btnquit" proc in global namespace. if you're using namespaces, have qualify command name. throw error when click button (invalid command name "btnquit")
namespace eval myspace { proc btnquit args {exit} } button .b -text quit -command btnquit
in case, need
button .b -text quit -command myspace::btnquit
if need pass arguments btnquit proc, you'll like
button .b -text quit -command [list btnquit $local_var1 $local_var2]
or
button .b -text quit -command {btnquit $global_var1 $global_var2}
the different quoting mechanisms cause variables substituted @ different times:
- the first when button created;
- the second when button clicked.
Comments
Post a Comment