So I have this project where a scanner scans a barcode (which works as if a keyboard entered in the input) and I want it to have it print out the input once there is a change in the "Entry" box but instead it is printing out an empty string and I used a list on it just to see if it was an empty string or something else. This is a snippet of my project.
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("550x250")
self.title("Testing Proctor Reader")
self.mainPage()
def mainPage(self):
for i in self.winfo_children():
i.destroy()
self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(2, weight=1)
startBtn = tk.Button(self, text='Start Scanning',bg="green",fg="white", command=self.scannerStart)
startBtn.grid(row=1, column=1, padx=20, pady=20)
startBtn.grid_rowconfigure(0, weight=1)
startBtn.grid_columnconfigure(0, weight=1)
def inputChange(self):
print([self.userInput.get()])
self.userInput.delete(0, 'end')
self.scannerStart()
def scannerStart (self):
for i in self.winfo_children():
i.destroy()
self.scanning = True
self.userInput = tk.Entry(self, validate="key", validatecommand=self.inputChange)
self.userInput.grid(row=2, column=1, padx=20, pady=20)
self.userInput.focus()
app = App()
app.mainloop()
the problem is somewhere around the self.userInput
and the inputChange()
function