Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.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 从Brother QL-800标签打印机打印标签_Python_Python 3.x_Windows 10 - Fatal编程技术网

Python 从Brother QL-800标签打印机打印标签

Python 从Brother QL-800标签打印机打印标签,python,python-3.x,windows-10,Python,Python 3.x,Windows 10,我正在尝试使用python脚本和brother_ql库从windows 10打印标签。如何创建和打印标签 使用PIL我已经创建了一个图像,我想有一个标签上打印。现在我想为我兄弟的QL-800标签打印机创建一个标签 from brother_ql import BrotherQLRaster, create_label from brother_ql.backends import backend_factory, guess_backend from brother_ql.devicedepen

我正在尝试使用python脚本和brother_ql库从windows 10打印标签。如何创建和打印标签

使用PIL我已经创建了一个图像,我想有一个标签上打印。现在我想为我兄弟的QL-800标签打印机创建一个标签

from brother_ql import BrotherQLRaster, create_label
from brother_ql.backends import backend_factory, guess_backend
from brother_ql.devicedependent import models, label_type_specs, 
label_sizes
from PIL import Image

LABEL_SIZES = [(name, label_type_specs[name]['name']) for name in 
label_sizes]
model = [m for m in models]
printer_model = model[9]  #QL-800
label_type = LABEL_SIZES[12]  #('29x90', '29mm x 90mm die-cut')

im = Image.open('tempQR.png', 'r')
im = im.resize((306, 991))
qlr = BrotherQLRaster(printer_model)

label = create_label(qlr, im, label_size='29x90', threshold=70, cut=True, 
rotate=0)

我知道这是一个有一年历史的问题,但我还没有在互联网上找到任何发布的文档,所以就在这里。我为自己弄清楚这件事玩得很开心

从这里阅读“后端”部分:下载并运行windows usb驱动程序过滤器。如果你还没有读过,那么整页都值得一读

我已经在Windows 10和运行Raspbian的Raspberry pi 4上测试了这段代码

from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster

im = Image.open('tempQR.png')
im.resize((306, 991)) 

backend = 'pyusb'    # 'pyusb', 'linux_kernal', 'network'
model = 'QL-800' # your printer model.
printer = 'usb://0x04f9:0x209b'    # Get these values from the Windows usb driver filter.  Linux/Raspberry Pi uses '/dev/usb/lp0'.

qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True

instructions = convert(

        qlr=qlr, 
        images=[im],    #  Takes a list of file names or PIL objects.
        label='29x90', 
        rotate='90',    # 'Auto', '0', '90', '270'
        threshold=70.0,    # Black and white threshold in percent.
        dither=False, 
        compress=False, 
        red=False,    # Only True if using Red/Black 62 mm label tape.
        dpi_600=False, 
        hq=True,    # False for low quality.
        cut=True

)

send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)
这基本上是brother_ql库文件“cli.py”中的“print_cmd”函数