1

I am working on a piece of GUIzero code intended to attach the values of a 2D array to a selection of textbox widgets. However, despite the fact that all variables in the widget value equations are forced to be strings, it still is telling me that a value is an integer.

    leaderboard_array = ["***", 0]*5
    leaderboard_box1 = Text(leaderboard_window)
    leaderboard_box1.value = str(str(leaderboard_array[0][0]) + ": " + str(leaderboard_array[0][1]))
    leaderboard_box2 = Text(leaderboard_window)
    leaderboard_box2.value = str(str(leaderboard_array[1][0]) + ": " + str(leaderboard_array[1][1]))
    leaderboard_box3 = Text(leaderboard_window)
    leaderboard_box3.value = str(str(leaderboard_array[2][0]) + ": " + str(leaderboard_array[2][1]))
    leaderboard_box4 = Text(leaderboard_window)
    leaderboard_box4.value = str(str(leaderboard_array[3][0]) + ": " + str(leaderboard_array[3][1]))
    leaderboard_box5 = Text(leaderboard_window)
    leaderboard_box5.value = str(str(leaderboard_array[4][0]) + ": " + str(leaderboard_array[4][1]))

The exact error code is this: leaderboard_box2.value = str(str(leaderboard_array[1][0]) + ": " + str(leaderboard_array[1][1])) TypeError: 'int' object is not subscriptable

2 Answers2

1

leaderboard_array[1][0] is indexing the second item of leaderboard_array which is a 0 (which is an int). I think you meant to have leaderboard array be a list containing more lists within it, which you can get by replacing line 1 with leaderboard_array = [["***", 0]] * 5 using two sets of []

Lecdi
  • 2,189
  • 2
  • 6
  • 20
0

Based on your question, it seems like the error is coming from this line:

leaderboard_box2.value = str(str(leaderboard_array[1][0]) + ": " + str(leaderboard_array[1][1]))

Where the error lies is that when you call leaderboard_array[1], the value in the 1st index position of the leaderboard array is an integer of some kind. In your code, by calling:

leaderboard_array[1][1]
# or
leaderboard_array[1][0]

You are trying to index an integer, which is not possible. I would recommend printing out what leaderboard_array[1] is to get a better idea as to why this error is occurring.

Mitchnoff
  • 495
  • 2
  • 7