i have a c_ui.py which only has codes to construct GUI by tkinter, and i put those Entry widgets in the list :list_widget_cost_dig
i would like to limit user's input by only digits, if not, the entire Entry will be deleted and that function"Check_Number" works fine.
the problem is that it only binds function to the last one widget in the widget list "list_widget_cost_dig", which is c_ui.entry_cost_price3.
list_widget_cost_dig = [c_ui.entry_cost_qty1,c_ui.entry_cost_price1,
c_ui.entry_cost_qty2,c_ui.entry_cost_price2,
c_ui.entry_cost_qty3,c_ui.entry_cost_price3]
def Check_Number(digit,widget):
x = re.search("[^0-9.]|.\d{4}|\.{2}|\.\d{2}\.", digit)
if x != None:
widget.delete(0,'end')
for name in list_widget_cost_dig:
name.bind("<KeyRelease>", lambda e: Check_Number(name.get(),name))
if i try one by one to bind the Check_Number function to each Entry widget, it works totally fine...
like below
c_ui.entry_cost_qty1.bind("<KeyRelease>", lambda e:Check_Number(c_ui.entry_cost_qty1.get(),c_ui.entry_cost_qty1))