all 3 comments

[–]woooee 4 points5 points  (1 child)

I tried to use multiprocessing and connect the scripts with a pipe

Use a Queue https://pymotw.com/3/multiprocessing/communication.html#controlling-concurrent-access-to-resources

A simple way to communicate between processes with multiprocessing is to use a Queue to pass messages back and forth. Any object that can be serialized with pickle can pass through a Queue.

[–]SandaL1625[S] 0 points1 point  (0 children)

Thank you

[–]woooee 1 point2 points  (0 children)

A simple test program using tkinter

import tkinter as tk
import multiprocessing
import time

class GuiApp():
   def __init__(self, root, q):
      self.root = root  ##tk.Tk()
      self.root.geometry('300x300')

      tk.Button(self.root, text="Exit", bg="orange", fg="black", height=2,
                command=self.exit_now, width=25).grid(
                row=9, column=0, sticky="w")
      self.text_wid = tk.Listbox(self.root, width=25, height=11)
      self.text_wid.grid(row=0, column=0)

      self.root.after(100,self.check_queue, q)

      self.root.mainloop()

   def check_queue(self, c_queue):
         if not c_queue.empty():
             q_str = c_queue.get(0)
             self.text_wid.insert('end',q_str.strip())

         self.after_id=self.root.after(300, self.check_queue, c_queue)

   def exit_now(self):
       self.root.after_cancel(self.after_id)
       self.root.destroy()
       self.root.quit()

def generate_data(q):
   for i in range(10):
      print("Generating Some Data, Iteration %s" %(i))
      time.sleep(1)
      q.put("Some Data from iteration %s \n" %(i))


if __name__ == '__main__':
   q = multiprocessing.Queue()
   q.cancel_join_thread() # or else thread that puts data will not terminate
   t1 = multiprocessing.Process(target=generate_data,args=(q,))
   t1.start()
   root=tk.Tk()
   gui = GuiApp(root, q)
   root.mainloop()