Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll automatically within a Tkinter message window

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!")
like image 890
Philipp der Rautenberg Avatar asked May 01 '09 14:05

Philipp der Rautenberg


1 Answers

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

like image 190
Alex Martelli Avatar answered Sep 22 '22 18:09

Alex Martelli