0

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))

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • [link]https://stackoverflow.com/questions/10865116/tkinter-creating-buttons-in-for-loop-passing-command-arguments I've read and try methods in above link, but not working to me. ` Fu_Check = lambda name: (lambda p: Check_Number(name.get(),name)) for name in list_widget_cost_dig: name.bind("", Fu_Check(name)) ` but googled for alot of hours, i solved it by above code – figoisbest Jul 25 '23 at 03:36

0 Answers0