You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears you're making PySimpleGUI calls from a thread. You may even be "getting away with it". If tktiner catches you, your program will crash. PySimpleGUI wasn't written to be threadsafe either.
There is an easy way out however. window.write_event_value() is callable from a thread. With this call you can pass data through to your event loop and then have your event loop perform the operation. I recommend using tuples for this. If you use a tuple with your events, then you can have the first item in your tuple be an indicator that the event is from your thread, then have the next item indicate the operation.
Maybe an event like this if you want to print something to the element with the key '-ML-': ('-THREAD-', 'print', '-ML-')
window.write_event_value(('-THREAD-', 'print', '-ML-'), "this is what I want to print")
In your event loop you can then have
ifevent[0] =='-THREAD-':
# all of your thread based event processing...ifevent[1] =='print':
window[event[2]].print(values[event])
Would love to get to working on this issue ASAP, however currently my exams are going so unfortunately it has to wait. Thanks for pointing it out! I actually learnt of this after I had implemented everything, so I got a bit lazy and just never came down to doing it.
It appears you're making PySimpleGUI calls from a thread. You may even be "getting away with it". If tktiner catches you, your program will crash. PySimpleGUI wasn't written to be threadsafe either.
There is an easy way out however.
window.write_event_value()
is callable from a thread. With this call you can pass data through to your event loop and then have your event loop perform the operation. I recommend using tuples for this. If you use a tuple with your events, then you can have the first item in your tuple be an indicator that the event is from your thread, then have the next item indicate the operation.Maybe an event like this if you want to print something to the element with the key
'-ML-'
:('-THREAD-', 'print', '-ML-')
In your event loop you can then have
I did something like this when I added threading to an image restoration project I stumbled onto:
mizosoft/ImageRestorationAndEnhancement#2
Lots of different ways to do it. You'll find examples in the Demo Programs as well that use write_event_value
The text was updated successfully, but these errors were encountered: