title: How to deselect an item (or items) of a Tkinter ttk.Treeview?
body: <p>I'm having trouble trying to deselect a <code>Treeview</code> item while doing it from a callback of another widget. I managed to implement a working deselection on <kbd>ESCAPE</kbd> press with:</p>
  
  <pre><code>tree.selection_remove(tree.focus())
  </code></pre>
  
  <p>in a callback bound to a treeview object itself. It works only when the treeview has focus (but it's OK, that's a desired behavior). On the other hand trying the same from a callback of another widget doesn't work.</p>
  
  <p>I tried using:</p>
  
  <pre><code>tree.selection_clear()
  </code></pre>
  
  <p>as recommended <a href="https://stackoverflow.com/questions/45376198/how-to-unselect-row-in-a-ttk-treeview-in-tkinter/45376931">here</a>, but this does not work either.</p>
  
  <p><strong>Important</strong>: selecting items in the treeview from the same call with <code>tree.selection_add(iid)</code> works. The same as manipulating yet another widget (a combobox, and the widget doing the call is a frame). Based on this, I don't suppose the problem is due to some silly bug (a typo or something like that) in my code.</p>
  
  <p>My theory is being out of focus is a problem as it's the only difference I see between when the same code works with <kbd>ESCAPE</kbd> but not elsewhere, so I tried to gain focus with <code>tree.focus_set()</code> and <code>tree.focus_force()</code>, but that didn't change anything.</p>
  
  <p>I don't quite understand what <code>selection_clear()</code> is supposed to do. As <code>ttk.Treeview</code> inherits this method from <code>ttk.Misc</code> the documentation on this is scarse. I couldn't find anything on it <a href="http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm" rel="nofollow noreferrer">here</a> or <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Treeview.html" rel="nofollow noreferrer">here</a>. The only thing I found is a laconic:</p>
  
  <blockquote>
    <p>Clear the current X selection.</p>
  </blockquote>
  
  <p>from the Python shell help (what's the cryptic <code>X</code>, coordinates?)</p>
  
  <p>So how to accomplish so seemingly simple? Please help, I'm at a loss for ideas.</p>