我打印图片X。然后我尝试打印图片Y,但它会再次打印图片X,然后再打印Y。请问,如何从Python列表中删除图片X?

2024-05-29 03:52:50 发布

您现在位置:Python中文网/ 问答频道 /正文

此代码用于在brother QL-800打印机上打印用于新冠病毒-19筛查的徽章

我正在使用某人在这里创建的惊人代码https://github.com/pklaus/brother_ql/tree/142cf744d89a912df729bbf15d35468d780559df/brother_ql

显然,每次我调用convert()或send()函数时,python代码都会在列表中维护我正在打印的标记

所以每次我试着打印一个新的徽章,它首先打印所有的旧徽章

在我执行convert()和send()命令打印后,有人看到如何从列表中删除徽章图像吗

代码如下:

import pygame
import time
from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster
from brother_ql.backends import backend_factory, guess_backend
#####################################################################################################
### Test QR-800 Printer
#####################################################################################################

# Here I just get two images each of size 1044x696
image1 = Image.open('RedBlack1_1044x696.png')
image2 = Image.open('RedBlack2_1044x696.png')

backend = 'linux_kernel'    # 'pyusb', 'linux_kernel', 'network'
model = 'QL-800' # your printer model.
printer = '/dev/usb/lp0'    
qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True

badge = convert(
    qlr=qlr, 
    images=[image1],    #  Takes a list of file names or PIL objects.
    label='62red', 
    rotate='90',    # 'Auto', '0', '90', '270'
    threshold=70.0,    # Black and white threshold in percent.
    dither=False, 
    compress=False, 
    red=True,    # Only True if using Red/Black 62 mm label tape.
    dpi_600=False, 
    lq=False,    # True for low quality.
    no_cut=False
)
send(instructions=badge, printer_identifier=printer, backend_identifier=backend, blocking=True)
# THE ABOVE COMMAND PRINTS MY FIRST IMAGE (image1)

badge = convert(
    qlr=qlr, 
    images=[image2],    #  Takes a list of file names or PIL objects.
    label='62red', 
    rotate='90',    # 'Auto', '0', '90', '270'
    threshold=70.0,    # Black and white threshold in percent.
    dither=False, 
    compress=False, 
    red=True,    # Only True if using Red/Black 62 mm label tape.
    dpi_600=False, 
    lq=False,    # True for low quality.
    no_cut=False
)
send(instructions=badge, printer_identifier=printer, backend_identifier=backend, blocking=True)
# THE ABOVE COMMAND PRINTS BOTH IMAGES (image1 and image2).  Why is it printing image1 this time????

# QUESTION - HOW DO I PREVENT IT FROM PRINTING THE FIRST IMAGE TWICE?

Tags: 代码frombadgeimportsendbackendfalsetrue
1条回答
网友
1楼 · 发布于 2024-05-29 03:52:50

阅读文档here表明convert将当前图像的光栅化指令添加到发送到打印机的数据中。很可能,您需要在第二个send()之前重置要发送的数据

一种方法是在第二个convert()之前使用qlr = BrotherQLRaster(model),但我无法测试这一点来确定,因为我没有兄弟打印机

相关问题 更多 >

    热门问题