python - subprocess.call() interacting with GUI (Tkinter) -


is there way use subprocess.call() or subprocess.popen() , interact stdin via tkinter's entry widget, , output stdout text widget?

im not sure how approach this, new using subprocess module.

think i've got basics of using entry stdin subprocess. may have jiggle own needs (re: output text widget).

this example calls test script:

# test.py:  #!/usr/bin/env python = raw_input('type something!: \n') #the '\n' flushes prompt print 

that requires input (from sys.stdin) , prints it.

calling , interacting via gui done with:

from tkinter import * import subprocess  root = tk()   e = entry(root) e.grid()  b = button(root,text='quit',command=root.quit) b.grid()  def entryreturn(event):     proc.stdin.write(e.get()+'\n') # '\n' important flush stdin     e.delete(0,end)  # when press return in entry, use stdin  # , remove e.bind("<return>", entryreturn)  proc = subprocess.popen('./test.py',stdin=subprocess.pipe)  root.mainloop() 

now whatever typed entry e (followed return key), passed via stdin proc.

hope helps.


also check this ideas stdout of subprocess question. you'll need write new stdout redirect stdout textwidget, like:

class mystdout(object):     def __init__(self,textwidget):         self.textwidget = textwidget     def write(self,txt):         self.textwidget.insert(end,txt)  sys.stdout = mystdout(mytextwidget) 

but recommend reading other examples people have achieved this.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -