Posted to tcl by jeremy_c at Fri Feb 05 13:22:46 GMT 2010view raw
- package require Tk
- namespace eval ttk::combobox {
- proc CompleteEntry {path key} {
- if {[string length $key] > 1 && [string tolower $key] != $key} {return}
- set values [$path cget -values]
- set x [lsearch -nocase $values $key*]
- if {$x < 0} {return}
- set index [$path index insert]
- $path set [lindex $values $x]
- $path icursor $index
- $path selection range insert end
- }
- proc CompleteList {W key} {
- for {set idx 0} {$idx < [$W size]} {incr idx} {
- if {[string match -nocase $key* [$W get $idx]]} {
- $W selection clear 0 end
- $W selection set $idx
- $W activate $idx
- break
- }
- }
- }
- }
- bind ComboboxListbox <KeyPress> { ttk::combobox::CompleteList %W %K }
- bind TCombobox <KeyPress> { ttk::combobox::CompleteEntry %W %K }
- set values {One Two Three Four Five Six Seven Eight Nine Ten}
- ttk::label .l1 -text Readonly
- ttk::combobox .c1 -state readonly -values $values
- ttk::label .l2 -text Editable
- ttk::combobox .c2 -values $values
- pack .l1 .c1 .l2 .c2