Код не может сказать, когда кто-то выигрывает игру, хотя он определен
Я пытался использовать if вместо elifs, но это приводит только к огромному количеству ошибок.
Я также пытался по-разному создавать отступы для кнопок (ттт), но это не приводит к отображению кнопок на экране
bclick = True
# Creates the "start" button and imports the tic-tac-toe frame
def start():
tk=Tk()
tk.title("Tic Tac Toe")
global bclick
bclick = True
def ttt(buttons):
# Handles left clicks and forces to appear a circle after an X
global bclick
if buttons["text"] == " " and bclick == True:
buttons["text"] = "X"
bclick = False
elif buttons["text"] == " " and bclick == False:
buttons["text"] = "O"
bclick = True
# Defines all the squares as 1-9 so we can know when someone wins
# Tells if "X" won the game
elif(button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button4['text'] == 'X' and button5['text'] == 'X' and button6['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!") #789
elif(button7['text'] =='X' and button8['text'] == 'X' and button9['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button1['text'] == 'X' and button5['text'] == 'X' and button9['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button3['text'] == 'X' and button5['text'] == 'X' and button7['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button1['text'] == 'X' and button4['text'] == 'X' and button7['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button2['text'] == 'X' and button5['text'] == 'X' and button8['text'] == 'X'):
tkinter.messagebox.showinfo("Player X","Winner is X !!!")
elif(button7['text'] == 'X' and button6['text'] == 'X' and button9['text'] == 'X'):
tkinter.messagebox.showinfo("Player X",'Winner is X !!!')
# Tells if "O" won the game
elif(button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O'or
button4['text'] == 'O' and button5['text'] == 'O' and button6['text'] == 'O'or
button7['text'] == 'O' and button8['text'] == 'O' and button9['text'] == 'O'or
button1['text'] == 'O' and button5['text'] == 'O' and button9['text'] == 'O'or
button3['text'] == 'O' and button5['text'] == 'O' and button7['text'] == 'O'or
button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O'or
button1['text'] == 'O' and button4['text'] == 'O' and button7['text'] == 'O'or
button2['text'] == 'O' and button5['text'] == 'O' and button8['text'] == 'O'or
button7['text'] == 'O' and button6['text'] == 'O' and button9['text'] == 'O'):
tkinter.messagebox.showinfo("Player O",'Winner is O !!!!')
tk.mainloop()
frame.start()