[Idle-dev] How to run idle.py from embedded python in another application

Terry Reedy tjreedy at udel.edu
Sat Sep 27 06:39:08 CEST 2014


On 9/23/2014 2:09 AM, 暮如雪 wrote:
> hi, All:
>
>      I am using embedded python in an MFC application, I need the
> embedded python interpreter to do some calculation, and now, I want it
> to do more, I need to open the python editor, like what can be done from
> IDLE GUI, where you can open FileList.py under libs\idle\ sub folder in

The directory is Lib/idlelib.  However, Idle is a application. Directly 
importing modules within idlelib is not supported.  Their names and APIs 
are mostly private; see PEP 443.

However, you have at least 3 other choices:

1. "import idlelib.idle" should start Idle properly.

2. run "python -m idlelib" in a subprocess should do it also.

3. Idle has a lot a baggage that you may not want. Instead, import 
tkinter and build a simple app around a Text widget.

Here is a copy of what I recently posted to python-list.
---
Most Python installations have tkinter available. I quickly wrote an 
absolutely minimal script.

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

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 IDLE-dev mailing list