title: Tkinter - logging text in Text Widget
body: <p>I want to do a class that is able to "log" text in a Text Widget. This class could be used by other applications to send and display logs to the text widget.</p>
  
  <pre><code>class TraceConsole():
  
      def __init__(self):
          # Init the main GUI window
          self._logFrame = Tk.Frame()
          self._log      = Tk.Text(self._logFrame, wrap=Tk.NONE, setgrid=True)
          self._scrollb  = Tk.Scrollbar(self._logFrame, orient=Tk.VERTICAL)
          self._scrollb.config(command = self._log.yview) 
          self._log.config(yscrollcommand = self._scrollb.set)
          # Grid &amp; Pack
          self._log.grid(column=0, row=0)
          self._scrollb.grid(column=1, row=0, sticky=Tk.S+Tk.N)
          self._logFrame.pack()
  
  
      def log(self, msg, level=None):
          # Write on GUI
          self._log.insert('end', msg + '\n')
  
      def exitWindow(self):
          # Exit the GUI window and close log file
          print('exit..')
  </code></pre>
  
  <p>Usage exemple:</p>
  
  <pre><code>t = TraceConsole()
  t.log('hello world!')
  </code></pre>
  
  <p>My problem now is that I don't know where to put the mainloop. This logger must run "in background" and it shall be possible to write log at any time until the window is closed.</p>