0
BuchstabenOptionen = Toplevel()
BuchstabenOptionen.attributes('-fullscreen',True)
BuchstabenOptionen.title("Buchstabenoptionen")


def BuchstabenAuswertung():
    hallo = Button_Buchstaben['text']


listeBuchstaben = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
row_Buchstaben = 0
column_Buchstaben = 0
    
for x in listeBuchstaben:
    global text
    print(x)
    row_Buchstaben = row_Buchstaben + 1
    if row_Buchstaben == 5:
        column_Buchstaben = column_Buchstaben +1
        row_Buchstaben = 1
    
    Button_Buchstaben =  Button(BuchstabenOptionen, text = x, font = BuchstabenFont, command = BuchstabenAuswertung).grid(row = row_Buchstaben, column = column_Buchstaben, padx = "5", pady = "5")

Code is returning hallo = Button_Buchstaben['text'] TypeError: 'NoneType' object is not subscriptable

What did i wrong?

  • Move the ```grid``` to next line. It returns ```None``` which you are trying to fetch –  Jun 30 '21 at 00:53

1 Answers1

0

All geometry managers: pack,place or grid return None. That is why it was throwing the error. So you should do something like this

Button_Buchstaben =  Button(BuchstabenOptionen, text = x, font = BuchstabenFont, command = BuchstabenAuswertung)
Button_Buchstaben.grid(row = row_Buchstaben, column = column_Buchstaben, padx = "5", pady = "5")

Also,your Button_Buchstaben is constantly updated to a new value. So when you click on it, only the last value will be printed. Update your function to this

def BuchstabenAuswertung(text):
    print(text)

We will create a local variable for each iteration and pass it as a parameter for the function.

Button_Buchstaben =  Button(BuchstabenOptionen, text = x, font = BuchstabenFont, command = lambda i=x:BuchstabenAuswertung(i))