title: An autocompleting combobox
body: <p>I'm trying to extend the behaviour of ttk::combobox to make it behave like the Google search box in my browser - i.e. I'd like it to drop down automatically and limit the entries in the listbox to those which match the string that I've typed in so far. Ultimately, I'd like to select the part of the string that's been autocompleted so that the next character the user types will cause it to be deleted and re-start the matching process.</p>
  <p>I found the page on the <a href="http://wiki.tcl.tk/15780" rel="nofollow noreferrer">Tcler's wiki</a>, but that appears to select the entry with the letter just typed, which isn't what I want. (Consider a user selecting from a list of US States. When they type A, I want the selection to be limited to Alabama, Alaska, Arizona and Arkansas; when they then type an L, the list should be limited to Alabama and Alaska. The code on the wiki would select Alabama when the user types A, then Louisiana when they type L.)</p>
  <p>I tried defining a few bindings on the ttk::combobox, but gave that up - to be honest, I can't remember why - and have tried to extend the behaviour of a ttk::entry to cover it.</p>
  <p>After borrowing liberally from ttk/combobox.tcl I've managed to post a listbox and to limit the entries in the listbox, but am having big problems now that I've added bindings to make the up and down arrows alter the selection. To be precise, the selected item is moved happily, but <em>some</em> of the time when the entry widget loses focus, the whole application hangs up and my tclsh soaks up all the CPU.</p>
  <p>I'm developing using ActiveTcl 8.6 on both Windows and Linux and the code seems to behave the same on both platforms, although I haven't tried on Linux since I first saw it <em>not</em> hanging in Windows. I'd be very happy to share my code, but since the demo script runs to about 450 lines, I wouldn't read it myself if someone else posted that much.</p>
  <p>Can anyone help by asking the right question to set off a lightbulb for me? The problem feels like a timing problem, but I've no idea where to start trying to track it down.</p>
  <p>Many thanks.</p>
  <p><strong>Edit</strong> I've been racking my brain, and I think the reason I abandonned the attempt to extend ttk::combobx was because there were already a large number of bindings in place, and some did things that I didn't want. The current effort uses a <em>validatecommand</em> on the entry widget and Key-Up, Key-Down, FocusIn and FocusOut bindings.</p>
  <p>Current code is on pastebin <a href="http://pastebin.com/f0q2gRFS" rel="nofollow noreferrer">here</a>.</p>