如何在Tkinter消息窗口中自动滚动 [英] How to scroll automatically within a Tkinter message window

查看:129
本文介绍了如何在Tkinter消息窗口中自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下用于在额外窗口中产生监视"输出的类.

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

  1. 不幸的是,它不会自动向下滚动到最新行.怎么了?
  2. 由于Tkinter和ipython也有问题,qt4的等效实现看起来如何?

这是代码:

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()

用法:

Monitor.write("Hello World!")

推荐答案

在一个调用插入语句之后立即添加一个语句cls.text.see(Tkinter.END).

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

这篇关于如何在Tkinter消息窗口中自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆