Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tk: scope problem

Status
Not open for further replies.

ginevra1971

Programmer
Sep 28, 2004
2
IT
Hello, I have a problem with my tcl program.
At the end of this message there is my program. The bold line causes an error when I try to execute it.
The error is "can't read time, no such variable".
I believe it's a scope problem but I can't solve it.
I'm waiting for a solution. Thanks

proc show {value label} {
tk_messageBox -message $value
$label config -text "new label"
}

proc run_gui {} {
wm withdraw .
set w3 .gui
catch { destroy $w3 }
toplevel $w3
#### frame OK e Cancel ###
frame $w3.frame_button
button $w3.frame_button.ok -text " OK " -command {}
button $w3.frame_button.cancel -text " Cancel " -command "destroy $w3"
pack $w3.frame_button.ok $w3.frame_button.cancel -side left -expand 1 -padx 2m
pack $w3.frame_button -side bottom -fill x -pady 2m

# frame input tempo-stato
set frame_input $w3.frame_input
frame $frame_input
pack $frame_input -side top
set entry_time $frame_input.entry_time
set lab_time $frame_input.lab_time
entry $entry_time -relief sunken -textvariable var_time
label $lab_time
$lab_time config -text Time

button $frame_input.btn_insert -text "Show" -width 10 -command [list show $time $lab_time]

grid $lab_time -row 0 -column 0 -rowspan 1 -columnspan 1 -padx 2m
grid $entry_time -row 1 -column 0 -rowspan 1 -columnspan 1 -padx 2m -pady 1m
grid $frame_input.btn_insert -row 1 -column 2 -rowspan 1 -columnspan 1 -padx 2m -pady 2m
raise $w3
focus "$entry_time"
}

run_gui
 
I think I see a couple of problems, at least things I don't understand.

First of all, you haven't defined a variable called "time", rather one called "var_time" (the textvariable of your entry, "entry_time"). That's probably the problem you're having, rather than scope; var_time is in the same scope as your gui.

Apart from that, I don't follow what you're trying to do with your command "[list show $time $lab_time]". As I read that, when the user presses the button, .gui.frame_button.frame_input.btn_insert, Tcl will create a list that has no associated variable name and that contains the word "show" followed by the value of the variable "time" (which doesn't exist), followed by the string "gui.frame_button.frame_input.lab_time". Is that what you intended?

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top