Application console for Tkinter program?

Christian Gollwitzer auriocus at gmx.de
Sat Mar 5 02:52:12 EST 2016


Hi all,

is there an easy way to add an application console to a Tkinter program? 
For instance, can you embed IDLE into a program such that when a button 
is pressed, it pops up a REPL window where the running program can be 
examined?

Say, there is a simple program like:

====================
import Tkinter as tk

def runshell():
	from idlelib.PyShell import main
	main()

root=tk.Tk()
nvar=tk.StringVar(root)
en=tk.Entry(textvariable=nvar)
en.pack()

btn=tk.Button(text="Shell", command=runshell)
btn.pack()

root.mainloop()
====================

I want the button to popup a shell window, and then nvar.get() should 
give me whatever is currently written in the entry. The code above does 
not work as intended, it pops up a shell, but:

1) I can't reach the variables from the main program, i.e. print(nvar) 
gives me a NameError

2) If you click the Shell button twice, it locks up the program, because 
main() obviously starts it's own mainloop


	Christian



More information about the Python-list mailing list