How to embed a terminal in a Tkinter application?

后端 未结 2 1001
無奈伤痛
無奈伤痛 2020-11-28 09:01

I want to embed a terminal in my main Tkinter window. I would like to have a sub window where a terminal (Bash based terminal) would run. I would like also to be able to let

相关标签:
2条回答
  • 2020-11-28 09:17

    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.

    0 讨论(0)
  • 2020-11-28 09:36

    Alessandro already reported five hours before what he regards as an adequate model. For those who come across this item during future searches, I'll record a few more background facts I know:

    It was fortunate that Bryan was here to draw attention to the differences between window_id() and winfo_id(), and to counter the errors others made in writing about various toolkits.

    It's interesting to me how stackoverflow compares to more specialized channels. In this case, the Tkinter mailing list http://mail.python.org/pipermail/tkinter-discuss/2011-September/002968.html swiftly and accurately responded to the question.

    Tkinter would be an improvement on at least some of the moon-rocket software.

    0 讨论(0)
提交回复
热议问题