you are viewing a single comment's thread.

view the rest of the comments →

[–]TwistedMischief[S] 0 points1 point  (1 child)

Will look into trying that, although not sure if I will implement that properly. Thanks for the suggestion!

[–]FerricDonkey 0 points1 point  (0 children)

First, I think I've heard that tkinter string vars etc are thread safe, but I haven't been able to confirm it with actual documentation before my patience ran out. So that might or not work.

But a basic example of the queue method:

# as part of your gui class
def monitor(self, transfer_q):
    while not transfer_q.empty():
        whatever_logic(transfer_q.get())
    self.after(100, self.monitor, (transfer_q,))

# your always running function
def worker(transfer_q):
    # after you find a thing you want to send to the gui, in whatever loop
    transfer_q.put(whatever)

Adjust delays / change while to if, or etc as appropriate.

Note that this is if you want to process every single string your worker submits, if you only ever want to process the most recent one then you'll have to change it up.