我正在使用validatecommandTkinterEntry框的選項來獲取用戶輸入的值并在資料庫中對其進行驗證。這對每個Entry小部件成功運行一次。
問題是,對于同一個小部件,該事件不會再次觸發,例如,如果用戶回傳進行更正。如何在Entry小部件上重置驗證,以便在用戶稍后回傳框時可以再次執行它?
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.
uj5u.com熱心網友回復:
有路徑通過isOkay不回傳True或False。驗證函式必須回傳一個布林值,否則它將被禁用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/365160.html
上一篇:Tkinter條目未更新
