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

Setting the max length of a text widget

Status
Not open for further replies.

anirban2k2001

Programmer
Aug 25, 2003
27
0
0
IN
How can I set the maximum length of a text entry widget in TCL?
I am giving the code below where I want to implement this.
I want to set the maximum length of the text widget .f2.t1 to 50 characters

CODE:

label .f2.l1 -text "Name" -font $fnt9
place .f2.l1 -x 0 -y 25

text .f2.t1 -bd 1 -highlightbackground black -highlightthickness 1 -font $fnt9
.f2.t1 insert end []
place .f2.t1 -x 65 -y 25 -width 170 -height 16

Any help will be highly appreciated.

Regards,
Anirban Sarkar
 
I don't think you can do what you want with a text widget. Consider, given that your max length is 50 characters, using an "entry" widget. With that, you can use the -validate option to check after the user has finished and take any action you want.
For example:

entry .f2.e1 -validate focusout -validatecommand {set egood [chkentry $evar]} -textvariable evar
pack .f2.e1


proc chkentry {evar} {
set flag 1
if {[string length $evar] > 50} {
set ::evar "entry must be <= 50 chars"
set flag 0
}
return $flag
}


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

Part and Inventory Search

Sponsor

Back
Top