私のコード「TypeError:文字列インデックスは整数でなければなりません」からこのエラーを理解できません。すでにコードに整数を渡す:文字列インデックスはforループからの整数エラーでなければなりませんが、整数を渡しています
def col1_button_click(self, x, y):
p = self.players_lst[self.currnt_player_index]
for x in range(6,0,-1):
if self.buttons_2d_list[x][0]["text"] == self.__space:
button = self.buttons_2d_list[x][0]
button["text"] = p.get_player_symbol()
self.gboard.make_move(x, 0, p.get_player_symbol())
winner = self.gboard.check_winner() # The board will check after each move, if any player has won the game
is_full = self.gboard.is_board_full()
if winner == True:
# Show current player's symbol as Winner,
# and terminate the game
win_messge = ("Player %s is the Winner!" % p.get_player_symbol())
messagebox.showinfo("Winner Info ",win_messge)
self.mw.destroy()
exit()
if is_full == True:
messagebox.showinfo("Winner Info", "The game ended in a draw!")
self.mw.destroy()
exit()
else:
pass
if self.currnt_player_index == 1:
self.currnt_player_index = 0
else:
self.currnt_player_index+=1 # increment index by 1
p = self.players_lst[self.currnt_player_index]
p.play()
エラーで、このラインから、第四1ダウン:
if self.buttons_2d_list[x][0]["text"] == self.__space:
が、私の理解から、私はすでにラインより上の範囲から整数を渡していますXの代わりに誰かが私が間違っていた場所を説明できるなら、私はとても感謝しています:)
テキストのような整数インデックスによって、その要素にアクセスする必要があります大丈夫です、それはtkinterボタンのテキストを取得しています。 xを任意の数に変更すると、その範囲がxに渡されていない理由が分かりません。 –