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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button Configure & command problem 1

Status
Not open for further replies.

godatguitar

Programmer
May 8, 2003
33
GB
Hi

I have started a new thread for this as I wasnt getting much of a reply in a different one - Hope you dont mind:

Here is the code for a button I have made, that will export the variable $result to an external file..... :



button $f.b -text "Submit Answers" -command {

set mark 0

# if the correct answer is chosen

if {$q1 == "0"} {incr mark}

if {$q2 == "1"} {incr mark}

if {$q3 == "2"} {incr mark}

set done 1

set result [expr {$mark * 100/3 }]
set fileId [open tmplgr "a"]
puts -nonewline $fileId "1"
puts $fileId $result
close $fileId

}


I need to disable the button once it has been pressed, and I need it to continue to do the rest of my code that is outside of a proc for various reasons:


ScrollableFrame .workspace
pack .workspace -expand yes -fill both

# Put the questions into the frame
Header .workspace.c.contents
Question .workspace.c.contents
Question1 .workspace.c.contents
Question2 .workspace.c.contents
Question3 .workspace.c.contents
Footer .workspace.c.contents

tkwait variable done

set q1 0
set q2 1
set q3 2

label .r -text "Your Result is $mark out of 3" -fg red
label .l -text "The Correct answers Have been selected for your reference."

pack .r -padx 0 -pady 0 -anchor n
pack .l -padx 0 -pady 0 -anchor n

#END OF PROGRAM



However, it only disables the button when I try and do this. Basically, I wanted to disable the submit button inside its -command { } , but I am unsure of how to do this.

Anyone got any ideas? I would luv to hear them.. Thanks

Paul
 
your code with one line added towards the end:


button $f.b -text "Submit Answers" -command {

set mark 0

# if the correct answer is chosen

if {$q1 == "0"} {incr mark}

if {$q2 == "1"} {incr mark}

if {$q3 == "2"} {incr mark}

set done 1

set result [expr {$mark * 100/3 }]
set fileId [open tmplgr "a"]
puts -nonewline $fileId "1"
puts $fileId $result
close $fileId


$f.b configure -state disabled

}


if you have already tried putting that last line in and you still cant continuing executing the rest of your code then I'm not sure how to help.

 
Hi

ALready done that mate, it doesnt let me do anything, but it does disable the button. But i need it to continue after that.
Thanks anyway

:)
 
It looks like the "rest of your code" is what happens after the "vwait" sees "done", right? The code looks ok but the behaviour might be because the variable, done, is set before the command is finished. Try moving "set done 1" to the last statement inside the command {}, i.e., right after smugI's addition.

Bob Rashkin
rrashkin@csc.com
 
Hi Bob


It cannot find the button $f.b inside its own command...

what do i do?

Its cannot find f, or .b if i change it to .b configure
 
somewhere you must have assigned "f". The steps inside the command {} are very much like a proc so variable assignment can be a little unexpected. I recommend you use the actual name for the button. So if your frame in which you have placed the canvas is, say, .frame1; then you put a text widget in the canvas, say, .frame1.cnvs1.txt1; then you "set f .frame1.cnvs1.txt1" and did your button magic; inside the button command, refer to the button as ".frame1.cnvs1.txt1.b".

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

Part and Inventory Search

Sponsor

Back
Top