【发布时间】:2023-04-08 08:01:01
【问题描述】:
我使用来自this question 的代码打印到热EPSON TM-T82 打印机,但是当我使用tkinter 和mainloop() 修改它时,python 不会直接打印出我的数据,直到我关闭我的布局GUI。我希望这个脚本可以在不关闭布局 GUI 的情况下打印出我的数据。
这是我的代码:
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()
【问题讨论】:
-
shell=True在那里没有做任何有用的事情。您不需要 shell 来运行单个命令(尽管您需要将lpr放入列表中:subprocess.Popen(['lpr'], stdin=subprocess.PIPE) -
你的代码没有调用
printData,我不希望它写任何东西。