consoleLog.py 859 B

123456789101112131415161718192021222324252627282930313233343536
  1. import queue as qu
  2. import tkinter
  3. class ConsoleLog(tkinter.Frame):
  4. def __init__(self, master=None):
  5. tkinter.Frame.__init__(self, master)
  6. self.queue = qu.Queue()
  7. self.text = tkinter.Text(self, highlightthickness=0, bd=0, bg='black', fg='white', relief='sunken',
  8. width=90, height=12)
  9. self.text.pack()
  10. self.sampler()
  11. def sampler(self):
  12. if self.queue.qsize():
  13. try:
  14. data = self.queue.get()
  15. self.text.insert('end', data)
  16. self.queue.task_done()
  17. except qu.Empty:
  18. pass
  19. self.after(50, self.sampler)
  20. def run(self):
  21. self.mainloop()
  22. def close(self):
  23. """Process before shutdown"""
  24. self.destroy()