Python标签打印机程序



我想打印两个标签,上面有相同的数字。我用ZPL。我已经在ZPL中制作了我的打印格式,它工作正常。我正试图打印一个数据范围。例如:

"范围内的第一个数字是什么?">用户输入100
"范围内的第二个数字是什么?">用户输入120

我将得到顺序的40个标签。
然后我希望它将数据导出到记事本文件中,然后将其打印到我的默认打印机。我的问题是,打印与ZPL我必须"标签"我的数据范围与我的ZPL代码。我不知道如何得到我的数据范围进入我的打印语句正确。请帮助。提前感谢!

import os
import sys

start = int(input("Enter the start of range: "))
end = int(input("Enter the end of range: "))

with open('TestFile.txt', 'a') as sys.stdout:
print('^XA')
print('^PQ2')
for labelRange in range(start, end + 1):
print('^FO185,50^A0,300^FD')(labelRange, end = " ")('^FS') 
#print('n')
print('^XZ')
os.startfile("C:/Users/joe.smith/desktop/TestFile.txt", "print")
exit()

这里有一些东西可以让你开始,但我怀疑它是完整的。您需要提供一个有效的ZPL文件来进行更改。

我也让程序现在使用固定的数字,所以它只是运行和输出。你可以把它改回来,一旦你让它工作。

start = 110
end = 111
notepad = ''
# these are header lines that go once (if windows you might need rn instead of n)
notepad += '^XAn'
notepad += '^PQ2n'
for label in range(start, end + 1):
# use f-strings
notepad += f'^FO185,50^A0,300^FD{label}^FSn'
# if you need some of those other numbers to increment
# then setup a counter and do the math here inside the f-string
notepad += f'^FO185,50^A0,300^FD{label}^FSn'
notepad += '^XZn'
# with open('tf.txt', 'w') as sys.stdout:
#     print(notepad)
print(notepad)
exit()

输出:

^XA
^PQ2
^FO185,50^A0,300^FD110^FS
^FO185,50^A0,300^FD110^FS
^FO185,50^A0,300^FD111^FS
^FO185,50^A0,300^FD111^FS
^XZ

相关内容

最新更新