user3599280 user3599280 - 3 months ago 25
Python Question

tkinter populate treeview using threading pool

I'm looking for "best" way to populate treeview using threads.
I have multiple mail account which I'm checking for new emails.

My plan is to use

Queue
to store accounts which will be checked
using
check_mail
method. This method will return a list of new
mails.

Can I use another
Queue
which I will populate with new mails and
somehow loop while threads are alive?

Is there any thread-safe, good pattern to solve this?

Answer

Your question is very broad, so this answer will also be.

Generally speaking, tkinter doesn't play well with multi-threading. You can do it, but must make sure only the main thread interacts with the GUI. A common way to do this is to use the universal widget method after() to schedule handling of data going out to or being retrieved from background threads, typically via Queues, at regular intervals.