python - 如何在 Tkinter 消息窗口中自动滚动

标签 python qt qt4 tkinter ipython

我编写了以下类以在额外窗口中生成“监控”输出。

  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!")

最佳答案

在调用 insert 之后添加语句 cls.text.see(Tkinter.END)

关于python - 如何在 Tkinter 消息窗口中自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/811532/

相关文章:

python - 为什么它在 4d numpy 数组中显示不同的图像?

python - 如何检查字符串是否是python中的有效JSON

python - 将 QML 元素锚定到窗口

c++ - 禁用/启用 QCheckBox 文本

c++ - 为什么在使用 QList 时 std::sort 会崩溃?

c++ - 使用 QSettings 保存 QSpinBox 和 QComboBox 的组合

python - DisabledFunctionError : cv2. imshow() 在 Colab 中被禁用,因为它会导致 Jupyter session 崩溃

python - 异常类

c++ - 寻找合适的数据存储和搜索引擎

c++ - 使用 Qt 在 Mac 上设置表单行,如 iTunes 信息对话框