0
def i2():
    btn2['bg']='yellow'
def i3():
    btn3['bg']='yellow'
def i4():
    btn4['bg']='yellow'
def i5():
    btn5['bg']='yellow'
def i6():
    btn6['bg']='yellow'
def i7():
    btn7['bg']='yellow'
def i8():
    btn8['bg']='yellow'
def i9():
    btn9['bg']='yellow'
def i10():
    btn10['bg']='yellow'
def i11():
    btn11['bg']='yellow'
def i12():
    btn12['bg']='yellow'

I've been thinking about this issue for a long time how I can this statement short? plz help me..

joon
  • 1
  • Instead of all the different `btn` variables, put all the buttons in a list called `buttons`. Then you can do `for b in buttons: b['bg'] = 'yellow'`. Or you can have your function take an index, and do `buttons[i]['bg'] = 'yellow'` instead of having a different function per button. – Samwise Apr 19 '22 at 18:03
  • The linked dupe is unfortunately not very helpful for newbies, and might lead you down a bad path if you try to implement any of the answers that involve `getattr` or `locals`. Do *not* do any of those things. The main thing is to use lists or dictionaries *instead of* a bunch of numbered variables. – Samwise Apr 19 '22 at 18:05

0 Answers0