Are there any other methods to detect the key presses on tkinter?

Question:

I’m currently working on a personal project. I was planning to create a Secured Database where only people with Special ID’s are able to access by just swiping their IDs on the scanner to be able to enter. The problem is that whenever the IDs do get read, they don’t automatically return the input from the Entry box. Here’s my code as reference to what i’m talking about:

Entry1 = Entry(main, width = 20)
Entry1.pack()

lbl = Label(main, text = "a")
lbl.pack()
lb2 = Label(main, text = "a")
lb2.pack()
lb3 = Label(main, text = "a")
lb3.pack()

def find():
    with open(CsvFile, newline = '') as csvcsv:
        reader = csv.DictReader(csvcsv)
        barcode = Entry1.get()
        for row in reader:
            if barcode == row['Sample']:
                lbl.config(text = row[''])
                lb2.config(text = row[''])
                break
        else:
            lbl.config(text='Your not a registered User')


keyboard.on_press_key("ENTER", lambda _:find)

Button(main, text='search', command = find).place(x=100, y=170)

main.mainloop()

This just a sample code but if anyone has an answer, It’s appreciated…

Asked By: Koshi

||

Answers:

The problem is that whenever the IDs do get read, they don’t automatically return the input from the Entry box.

One possible solution to this problem is to use the .get() method on the Entry widget to retrieve the text inputted by the user.

Answered By: LuckyOwl
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.