Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从os.pipe()直接读取到Tkinter文本框_Python_Python 2.7_Tkinter_Pipe - Fatal编程技术网

Python 从os.pipe()直接读取到Tkinter文本框

Python 从os.pipe()直接读取到Tkinter文本框,python,python-2.7,tkinter,pipe,Python,Python 2.7,Tkinter,Pipe,我试图将单独脚本的输出路由到Tkinter窗口 下面是我对这个问题的尝试。Tkinter框出现,但在控制器(此处抽象)使用os.write(pipeout,msg)写入pipeout时不会更新 抽象控制器正在通过 os.write(self.pipeout, msg) 其中,self.pipeout已从控制器类self.pipeout=pipeout中指定init听起来好像您忘记刷新了 self.pipeout.write(msg) self.pipeout.flush() 另外,确保消息以

我试图将单独脚本的输出路由到Tkinter窗口

下面是我对这个问题的尝试。Tkinter框出现,但在控制器(此处抽象)使用os.write(pipeout,msg)写入pipeout时不会更新

抽象控制器正在通过

os.write(self.pipeout, msg)

其中,
self.pipeout
已从控制器类
self.pipeout=pipeout
中指定
init

听起来好像您忘记刷新了

self.pipeout.write(msg)
self.pipeout.flush()
另外,确保消息以换行结尾


编辑:您确定需要管道吗?不管你在做什么,可能都有更整洁的方法,比如穿线

解决方案来自于使用
os.read(pipein,100)
而不是
os.fdopen(pipein)
中的
updateInput

line = os.read(pipein, 100)
text.insert(END, line)
text.after(1000, updateInput)

运行
updateInput
时会发生什么情况?它会崩溃吗?它读错东西了吗?它是否阅读正常,但无法插入文本?问题从哪里开始?看起来你并没有在写任何东西,似乎没有从管道中读取数据。我在另一端使用os.write(self.pipeout,msg)语句写入管道,其中self.pipeout是指定的self.pipeout=pipeout。我会更新这个问题@“没有阅读”是什么意思?
updateInput
是否像您期望的那样被调用?你是说它正在被调用,但不知何故跳过了对
read
的调用?
line = os.read(pipein, 100)
text.insert(END, line)
text.after(1000, updateInput)