Python条码扫描器

Python barcode scanner

我已经在网站上阅读了有关如何仅从条形码扫描仪获取输入的信息,但我不确定我应该如何实际操作。

我将使用此条码扫描器:https://www.amazon.co.uk/Esky-Wireless-Handheld-Barcode-Rechargeable/dp/B00O9P3Z7C/ref=sr_1_6?ie=UTF8&qid=1482066778&sr=8-6&keywords=usb+barcode+scanner

当用户在我的 tkinter 中单击 return 按钮时,我基本上需要 window 我需要程序是一个 while 循环,直到从扫描仪收到输入,然后我将使用扫描仪查看它是否在我的数据库中。

我可以做 SQL 和其他所有事情,但我实际上不确定从条形码扫描仪中剥离数据的最佳方法是什么,因为它应该充当键盘。

编辑:我试过这个:

 barcode = simpledialog.askstring("Barcode scan", "Please scan the barcode of the laptop you rented")

cursor.execute("SELECT barcode FROM laptops WHERE idlaptops=%s",laptopid)
barcodefetch = fetchResult(cursor)
actualbarcode = barcodefetch[0]["barcode"]

if barcode != actualbarcode:
    messagebox.showinfo("Barcode invalid", "Barcode did not match please scan the barcode again")
    return

扫描仪会在询问字符串框中键入内容吗?

条形码扫描器被计算机视为键盘。 只要 window 中的文本字段具有焦点,当扳机被拉动时,代码就会在字段中键入,就像您使用键盘一样。