tkinter ttk iterating through treeview
<p>I an using a tkinter ttk GUI to present data on files in a server. The information is stored in a ttk treeview and presented as a table. The goal is for the user to be able to filter these rows so that functions can be performed only on those visible in the treeview after the user is done filtering.</p>

<p>Problem is, I can't find a way to iterate through the treeview. I need to be able to to do something like this:</p>

<pre><code>def filterTreeview(treeviewToFilter, tvColumn, stringVariable):
    for tvRow in treeviewToFilter:
        if tvRow.getValue(tvColumn) != stringVariable:
            tvRow.detach()
</code></pre>

<p>How can I achieve this?</p>

<p>As a secondary question, does anybody know of a better way to do this? Is there any reason to use a treeview rather than a simple array? What about making the filter on an array of data and then re-creating the treeview table from scratch?</p>

<p>I've spent a lot of time reading tutorials looking for information but I've not been successful in understanding the way to use data in a treeview so far:</p>

<p><a href="http://stackoverflow.com/questions/22032152/python-ttk-treeview-sort-numbers">python ttk treeview sort numbers</a>
<a href="http://www.tkdocs.com/tutorial/tree.html" rel="nofollow">http://www.tkdocs.com/tutorial/tree.html</a></p>

<p><a href="https://fossies.org/dox/Python-3.5.2/classtkinter_1_1ttk_1_1Treeview.html" rel="nofollow">https://fossies.org/dox/Python-3.5.2/classtkinter_1_1ttk_1_1Treeview.html</a> </p>

<p>To iterate through a treeview's individual entries, get a list of treeview item 'id's and use that to iterate in a 'for' loop:</p>

<pre><code>#Column integer to match the column which was clicked in the table
col=int(treeview.identify_column(event.x).replace('#',''))-1

#Create list of 'id's
listOfEntriesInTreeView=treeview.get_children()

                    for each in listOfEntriesInTreeView:
                        print(treeview.item(each)['values'][col])  #e.g. prints data in clicked cell                          
                        treeview.detach(each) #e.g. detaches entry from treeview
</code></pre>

<p>This does what I need but if there is a better way, please let me know.</p>

python tkinter treeview ttk