Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter - How to insert text at the beginning of the text box?

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

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?

Thanks.

like image 495
user2662241 Avatar asked Aug 20 '13 22:08

user2662241


1 Answers

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

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.

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.

like image 117
Brionius Avatar answered Oct 20 '22 05:10

Brionius