Editing text with an external editor in Python

Terry Reedy tjreedy at udel.edu
Tue Sep 2 23:14:28 CEST 2014

On 9/2/2014 4:45 AM, Chris Angelico wrote:
> On Tue, Sep 2, 2014 at 6:35 PM, alister
> <alister.nospam.ware at ntlworld.com> wrote:
>> if edlin is your only option then it would be better to spend you time
>> writhing your own text editor!
> Heh!
> Considering how easy it is to deploy a multi-line edit widget in any
> GUI toolkit, it shouldn't be too hard to write a GUI text editor.

Most Python installations have tkinter available. I quickly wrote an 
absolutely minimal script.

import tkinter as tk
root = tk.Tk()
text = tk.Text()

I tested tested the functions and wrote the following.

This is a test text entry.
Enter and Tab work as expected.
The Arrow (Cursor) keys work as expected.
CntL-Left and Cntl-Right move a word at time.
Home and End move to beginning and end of the line.
Cntl-Home and Cntl-Up move to the beginning of the text.
Cntl-End and Cntl-Donw move to the end of the text.
Shift + cursor movement selects between the begin and end slice positions.
PageUp and PageDown are inoperative.
Delete and Backspace work as expected.
At least on Windows, I can select text and delete,
or cut or copy to Clipboard.
I can also paste from the clipboard.
In otherwords, this is a functional minimal text entry widget.

I did not even know about Shift-movement selecting until I tried it.
Notepad has this. Thunderbird's text entry does not.

I think the above is adequate for most multi-line text entry.
In use, a save function would have to be added.
A help text with the above info would be good too (Idle needs this).

Terry Jan Reedy

More information about the Python-list mailing list