import win32com.client
class BartenderLabelPrint:
def __init__(self, btw):
self.btw = btw
self.btapp = win32com.client.Dispatch("BarTender.Application")
def create_new_label(self):
label = self.btapp.Formats.Open(self.btw, False, "")
return label
@staticmethod
def build_label(label, key, value):
label.SetNamedSubStringValue(key, value)
def print_label(self, label):
label.PrintOut(False, False)
label.Close(False)
self.btapp.Quit(0)
if __name__ == '__main__':
printer = BartenderLabelPrint(r'E:\打包模板.btw')
_label = printer.create_new_label()
printer.build_label(_label, 'CELL_MODEL', 'Test1')
printer.build_label(_label, 'BOX_NO', '0123456789')
printer.build_label(_label, 'MI', 'Test2')
printer.build_label(_label, 'PACK_DATE', '2022-02-02')
printer.build_label(_label, 'PACK_QTY', '222')