Python Tkinter - 如何在文本框的开头插入文本? [英] Python Tkinter - How to insert text at the beginning of the text box?

查看:41
本文介绍了Python Tkinter - 如何在文本框的开头插入文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Python 2.7.5 和 Tkinter.我正在将状态消息写入文本小部件.要插入我正在使用:

I am using Python 2.7.5 and Tkinter. I am writing status messages into a text widget. To insert I am using:

text_widget.insert(INSERT, 'my status here.\n')

这很好用.但是,每个状态都添加在前一个状态之后.如何在 Text 小部件的顶部插入新行,以便将最近的状态显示在顶部,同时将之前的状态消息保留在下方?

This works fine. However, each status is added after the previous status. How do I insert new lines at the top of the Text widget so that the most recent status is at the top, while keeping the previous status messages below?

谢谢.

推荐答案

text_widget.insert('1.0', 'my status here.\n')

简而言之,可以使用 "lineNum.columnNum" 形式的字符串表示法以及使用诸如 Tkinter.INSERT 之类的特殊索引来索引文本小部件.

In short, the text widget can be indexed using a string notation of the form "lineNum.columnNum", as well as using the special indices like Tkinter.INSERT.

我建议阅读 effbot 的 Tkinter 文本小部件文档,或 新墨西哥理工学院的 Tkinter 手册,我发现其中的示例和解释较少,但作为 API 参考更完整.

I would recommend reading effbot's documentation for the Tkinter text widget, or New Mexico Tech's Tkinter Handbook, which I've found has fewer examples and explanations, but is more complete as an API reference.

这篇关于Python Tkinter - 如何在文本框的开头插入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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