import tkinter import threading import queue import time # Data Generator which will generate Data def GenerateData(q): for i in range(1000000): #print "Generating Some Data, Iteration %s" %(i) time.sleep(0.001) q.put("%s" % i) # Queue which will be used for storing Data q = queue.Queue() def QueueHandler(widinst, q): linecount = 0 print("Running") while True: if not q.empty(): str = q.get() linecount = linecount + 1 widinst.configure(state="normal") str = str + "\n" widinst.insert("end", str) if linecount > 100: widinst.delete('1.0', 'end') linecount = 0 widinst.see('end') widinst.configure(state="disabled") # Create a thread and run GUI & QueueHadnler in it tk = tkinter.Tk() scrollbar = tkinter.Scrollbar(tk) scrollbar.pack(side='right', fill='y' ) text_wid = tkinter.Text(tk,yscrollcommand=scrollbar.set) text_wid.pack() t1 = threading.Thread(target=GenerateData, args=(q,)) t2 = threading.Thread(target=QueueHandler, args=(text_wid,q)) t2.start() t1.start() tk.mainloop()