python Tkinter Capturing keyboard events save as one single string

Viewed 943

is it possible to store keyboard events into one string? with the code below it only stores one char and prints it. but for a card reader or bar code reader, it contains a collection of character/ string not one character at a time. The goal is the save all the char pressed into text variable.

from tkinter import *

root = Tk()

def key(event):
     text= event.char
     text+= event.char
     print ("pressed", text)

def callback(event):
     frame.focus_set()
print ("clicked at", event.x, event.y)

frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.bind("<Button-1>", callback)
frame.pack()

root.mainloop()
1 Answers
Related