I need to embed an interative python interpreter into my tkinter program. Could anyone help me out as to how to integrate it?
I have already looked at the main()
function, but it's way to complex for my needs, but I can't seem to reduce it without breaking it.
Some details of what you must do may depend on what you want to do with IDLE's Shell once you have it running. I would like to know more about that. But let us start simple and make the minimum changes to pyshell.main needed to make it run with other code.
Note that in 3.6, which I use below,
PyShell.py
is renamedpyshell.py
. Also note that everything here amounts to using IDLE's private internals and is 'use at your own risk'.I presume you want to run Shell in the same process (and thread) as your tkinter code. Change the signature to
Change root creation (find
# setup root
) toIn current 3.6, there are a couple more lines to be indented under
if not tkroot
:Guard mainloop and destroy (at the end) with
The above adds 'dependency injection' of a root window to the function. I might add it in 3.6 to make testing (an example of 'other code') easier.
The follow tkinter program now runs, displaying the both the root window and an IDLE shell.
You should be able to call pyshell.main whenever you want.