0
아래 코드를 참조하십시오. 두 줄의 인쇄문 (# 1 및 # 2)을 실시간으로 (줄 단위로) 인쇄 할 수 있습니다. 그러나 텍스트 위젯은 서브 프로세스 csh 스크립트를 실행 한 후에 만 나타납니다.루프의 예기치 않은 텍스트 위젯 동작
하위 프로세스의 표준 출력에서받은 값을 인쇄 할 수있는 이유는 텍스트 위젯에 표시되지 않는 이유는 무엇입니까?
#!/tools//python/2.7.2/bin/python -u
import os
import ttk
from Tkinter import *
import subprocess
import sys
t = Tk()
t.title('New title')
t.geometry('800x1000-5+40')
t.state('normal')
little = Label(t, text="OUTPUT LOG").grid(column = 0, row = 0)
log = Text(t, state='normal', width=115, height=150, wrap='none')
log.grid(row = 1, column = 0)
test=subprocess.Popen("tem",shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
#tem is a csh file which print number from 1 to 1000
#stdout
cnt = 0.0
while True:
line = test.stdout.readline()
cnt += 1
if line == "":
break
else:
log['state'] = 'normal'
log.insert(cnt,line)
print 'line #' #1
print line #2
log['state'] = 'disabled'
t.mainloop()
루프 내부에 widget.update()를 추가하면 – Ani