How to make a tkinter GUI work on top of a CUI program?

Chris Angelico rosuav at gmail.com
Fri Jan 3 21:55:15 EST 2014


On Sat, Jan 4, 2014 at 1:44 PM, Beinan Li <li.beinan at gmail.com> wrote:
> But some console programs have their own shell or ncurse-like CUI, such as
> cscope.
> So I figured that I need to first subprocess.popen a bidirectional pipe and
> send command through stdin and get results from stdout and stderr.
>
> But in such a case I found that communicate('cmd') will freeze.

You can't use communicate(), as it'll wait for the process to end. But
there are several quite different types of console UI, some of which
you'll be able to use and some you won't:

1) There's the simple, straight-forward writing to stdout/stderr.
Maybe it's a long-running 'make' or the burning of a DVD, but whatever
it does, it takes no input and writes to the standard streams. Easy to
work with - just read and handle incoming text.

2) There are interactive shell-type systems. You'll need to send them
more than just lines of text, probably, as you might need to send
command keys and such. But still fairly workable.

3) Then there's stuff that doesn't actually use the standard streams
at all, or uses them and uses something else as well. You can pipe
something into 'less', but it'll still look for actual keyboard input
for its control. You'll have a lot more trouble manipulating those
programs.

Something that uses ncurses is most likely to land in box 3.

ChrisA



More information about the Python-list mailing list