I have a question about multiprocessing and tkinter. I am having some problems so that my process runs in parallel with the tkinter GUI. I created a simple practice example and read to understand the basics of multiprocessing. However, applying them to tkinter, only one process is running at this time. ( Using the Multiprocessing module to update the Tkinter GUI ) In addition, when I added a queue for communication between processes, ( How to use multiprocessing queue in Python? ), The process will not even start.
Purpose:
I would like to have one process that counts and puts the values ββin the queue, and one - update tkinter after 1 second and show me the values.
All tips are kindly appreciated.
Regards, S
EDIT : I want data to be available when the after method is called. Thus, the problem is not with the after function, but with the call to the after method. It will take 0.5 seconds to complete the calculation each time. Therefore, the GUI does not respond for half a second, every second.
EDIT2 : Corrections have been made to the code based on feedback, but this code has not yet been run.
class Countdown():
"""Countdown prior to changing the settings of the flows"""
def __init__(self,q):
self.master = Tk()
self.label = Label(self.master, text="", width=10)
self.label.pack()
self.counting(q)
def counting(self, q):
try:
self.i = q.get()
except:
self.label.after(1000, self.counting, q)
if int(self.i) <= 0:
print("Go")
self.master.destroy()
else:
self.label.configure(text="%d" % self.i)
print(i)
self.label.after(1000, self.counting, q)
def printX(q):
for i in range(10):
print("test")
q.put(9-i)
time.sleep(1)
return
if __name__ == '__main__':
q = multiprocessing.Queue()
n = multiprocessing.Process(name='Process2', target=printX, args = (q,))
n.start()
GUI = Countdown(q)
GUI.master.mainloop()
source
share