views:

212

answers:

1

Hello together,

I wrote the following class for producing "monitoring" output within an extra window.

  1. Unfortunately it doesn't scroll automatically down to the most recent line. What is wrong?
  2. As I also have problems with Tkinter and ipython: how would an equivalent implementation with qt4 look like?

Here is the code:

import Tkinter
class Monitor(object):
  @classmethod
  def write(cls, s):
    try:
      cls.text.insert(Tkinter.END, str(s) + "\n")
      cls.text.update()
    except Tkinter.TclError, e:
      print str(s)
  mw = Tkinter.Tk()
  mw.title("Message Window by my Software")
  text = Tkinter.Text(mw, width = 80, height = 10)
  text.pack()

Usage:

Monitor.write("Hello World!")

Cheers, Philipp

+3  A: 

Add a statement cls.text.see(Tkinter.END) right after the one calling insert.

Alex Martelli
Consider usability when doing this. For example, if the user has scrolled back up from the bottom to look at something you don't want to automatically scroll.
Bryan Oakley