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

disable button after initial selection

Status
Not open for further replies.

satguy

Programmer
Jun 30, 2005
6
US
How would one deselect or disable a button after it has been initially selected so it can't be selected again?
 
Code:
button .btn -text "Button" -command {
    # do stuff
    .btn configure -state disabled
}

-Bones
 
Bones3 -
Thanks for the input. I tried it and have not been able to successfully implement it. I am new to Tcl/Tk and am probably not invoking a proc just right. Here's my code with your additions in the button section.

(I have successfully set up the entries and the frame prior to the following code)
-------------------

# Define button
button .but -text "OK" -bg cyan -borderwidth 3 -command {
"write_file" .but configure -state disable
}
pack .but
#
proc write_file { } {
set out [open test w]
set field1 [.ent1 get]
set field2 [.ent2 get]
set field3 [.ent3 get]
set str [string lenght "$field1 get"]

if { $field1 == "" || $str >= 15 } {

frame .frmSub -borderwidth 5 -relief raised
label .labSub -text "\nIncorrect Entry.\n\n Hit Cancel and try again.\n"
pack .frmSub
pack .labSub -in frmSub
button .but1 -text "Cancel" -command "desThisWindow"
pack .but1 -in .frmSub

}elseif { $field2 == "" || $str >= 15 } {
# do stuff similar to first if

}elseif { $field3 == "" || $str >= 15 } {
# do stuff similar to first if

}elseif { $field2 != field3 } {
# do stuff similar to first if

}else {
# write data in entries to a file, close file and exit
}
}
proc desThisWindow { } {
destroy .
}

----------------

Any other suggestions as to how to get the button to be disabled would be apprciated.

 
Add a d to the end of disable, and separate your commands (with a semicolon or newline). I am sort of new to Tcl too, but I think you have to have "write_file" declaired before defining the button. write_file won't need quotes when you call it.

Code:
# Define button
button .but -text "OK" -bg cyan -borderwidth 3 -command {
  write_file; .but configure -state disabled
}

or

Code:
# Define button
button .but -text "OK" -bg cyan -borderwidth 3 -command {
  write_file
  .but configure -state disabled
}

I hope that helps.

-Bones
 
The 'd' helped as did placing the write_file proc before the button. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top