How to embed a terminal in a Tkinter application?

I am happy to say that it is in fact possible to do it, and you can do it with just a few lines of code (I don’t know if it is so easy with other toolkits):

from Tkinter import *
import os

root = Tk()
termf = Frame(root, height=400, width=500)

termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 40x20 -sb &' % wid)

root.mainloop()

The problem before was to use the wrong function for wid.

Leave a Comment