2016-09-26 2 views
0

열 EPSON TM-T82 프린터로 인쇄 할 때 this question의 코드를 사용하지만, tkintermainloop() python으로 수정 한 경우 레이아웃 GUI를 닫을 때까지 내 데이터를 직접 인쇄하지 마십시오. 이 스크립트가 레이아웃 GUI를 닫지 않고 내 데이터를 인쇄 할 수 있기를 바랍니다. 당신은 버퍼링 발생하는Popen 및 GUI tkinter 프린터로 인쇄하는 방법

import subprocess 
from Tkinter import * 

class tes_print: 
    def __init__(self): 
     self.printData() 

    def printData(self): 
     data = " MY TEXT " 
     lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE, shell=True) 
     lpr.stdin.write(data) 

root = Tk() 
app2 = tes_print() 
root.mainloop() 
+0

'shell = True'는 그곳에서 유용한 것을하지 않습니다. 'lpr'을리스트에 넣어야하지만 쉘을 사용할 필요는 없습니다 :'subprocess.Popen ([ 'lpr'], stdin = subprocess.PIPE)' – tripleee

+0

코드는 'printData'를 호출하면, 아무것도 쓰지 않을 것이라고 기대합니다. – Goyo

답변

0

:

내 코드입니다. write은 채워 지거나 명시 적으로 플러시 할 때까지 실제로 lpr으로 전달되지 않은 버퍼에 씁니다.

lpr.communicate()을 실행하면 플러시되어 lpr이 완료 될 수 있습니다.

lpr = subprocess.Popen(['lpr'], stdin=subprocess.PIPE) 
stdout, stderr = lpr.communicate(input=data) 
관련 문제