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

I print Picture X. I then try to print Picture Y but it prints Picture X again followed by Y. Please, how can I delete Picture X from a Python list?

此代码用于在兄弟 QL-800 打印机上打印用于 COVID-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?

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

之前重置要发送的数据

一种方法是在第二个 convert() 之前使用 qlr = BrotherQLRaster(model),但由于我没有 Brother 打印机,我无法对此进行测试以确定。