@@ -33,23 +33,24 @@ def the_gui(gui_queue):
3333 window = sg .Window ('Multithreaded Window' ).Layout (layout )
3434 # --------------------- EVENT LOOP ---------------------
3535 message = None
36+ count = 0
3637 while True :
3738 event , values = window .Read (timeout = 100 ) # wait for up to 100 ms for a GUI event
3839 if event is None or event == 'Exit' :
3940 break
4041 if event == 'Go' :
41- window .Element ('_OUTPUT_' ).Update ('Starting long work....' )
42+ window .Element ('_OUTPUT_' ).Update ('Starting long work %s' % count )
4243 # simulate STARTING long run by starting a thread
43- threading .Thread (target = worker_thread , args = ('Thread 1' , gui_queue ,), daemon = True ).start ()
44-
44+ threading .Thread (target = worker_thread , args = ('Thread %s' % count , gui_queue ,), daemon = True ).start ()
45+ count += 1
4546 # --------------- Loop through all messages coming in from threads ---------------
4647 try : # see if something has been posted to Queue
4748 message = gui_queue .get_nowait ()
4849 except queue .Empty : # get_nowait() will get exception when Queue is empty
4950 pass # nothing in queue so do nothing
5051
5152 # if message received from queue, display the message in the Window
52- if message is not None and message . startswith ( 'Thread 1' ) :
53+ if message is not None :
5354 # this is the place you would execute code at ENDING of long running task
5455 window .Element ('_OUTPUT_' ).Update (message )
5556 window .Refresh () # do a refresh because could be showing multiple messages before next Read
0 commit comments