I'm using the validatecommand
option of a Tkinter Entry
box to pickup the value entered by the user and validate it in a database. This works successfully once per Entry
widget.
Problem is, the event won't fire again a second time for the same widget, say if a user returns to make a correction. How can I reset validation on an Entry
widget so it can be executed again if the user returns to the box later?
def isOkay(root, why, where, barcode, name):
if (barcode != ''):
lookupFromBarcodeSql = "select Manufacturer, Brand, Model, Submodel, Size from Drives where Submodel = %s and Manufacturer = 'Seagate' and Brand != '' and Brand is not null and Model != '' and Model is not null and Submodel != '';"
lookupFromBarcodeParams = (barcode.strip(),)
myCursor.execute(lookupFromBarcodeSql, lookupFromBarcodeParams)
lookupResults = myCursor.fetchall()
for result in lookupResults:
print(result[0] " " result[1] " " result[2] " " result[4])
checkAgainstDb, = root.register(isOkay)
lidBarCode = Entry(BarCodeFrame, validate="focusout",validatecommand=(checkAgainstDb, '%d','%i','%S','%P','%W'))
The callback function is unfinished code but is only called once, as evidenced by the print statement only firing once.
CodePudding user response:
There are paths through isOkay
that do not return True
or False
. Validation functions must return a boolean value or it will get disabled.