Frage von PythonDuude, 36

Kann mir wer sagen wo in dem python Tic Tac Toe script der syntex Fehler ist?

from tkinter import*

import tkinter.messagebox tk = tk() tk.title("Tic Tac Toe")

click = True

def checker(buttons) :
global click if buttons["text"] == " " and click == True: buttons["text"] = "X"
click = False elif buttons ["text"] == " " and click == False: buttons["text"] = "O"
click = True

    elif(button1["text"] == "X" and button2["text"] == "X" and button3["text"] == "X" or
         button4["text"] == "X" and button5["text"] == "X" and button6["text"] == "X" or
         button7["text"] == "X" and button8["text"] == "X" and button9["text"] == "X" or
         button3["text"] == "X" and button5["text"] == "X" and button7["text"] == "X" or
         button1["text"] == "X" and button5["text"] == "X" and button9["text"] == "X" or
         button1["text"] == "X" and button4["text"] == "X" and button7["text"] == "X" or
         button2["text"] == "X" and button5["text"] == "X" and button8["text"] == "X" or
         button3["text"] == "X" and button6["text"] == "X" and button9["text"] == "X"):
        tkinter.messagebox.showinfo("Der Gewinner ist X !!!")




    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
         button3["text"] == "O" and button5["text"] == "O" and button7["text"] == "O" or
         button1["text"] == "O" and button5["text"] == "O" and button9["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
         button3["text"] == "O" and button6["text"] == "O" and button9["text"] == "O"):
        tkinter.messagebox.showinfo("Der Gewinner ist O !!!")

buttons=StringVar()

button1 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button1))

button1.grid(row=1, column=0,sticky = S+N+E+W)

button2 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button2))

button2.grid(row=1, column=0,sticky = S+N+E+W)

button3 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button3))

button3.grid(row=1, column=0,sticky = S+N+E+W)

button4 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button4))

button4.grid(row=1, column=0,sticky = S+N+E+W)

button5 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button5))

button5.grid(row=1, column=0,sticky = S+N+E+W)

button6 = Button(tk,text=" ",font=(('Times 26 bold'),high = 4 , wifth =8, command=lambda:Checker(button...

Antwort
von LifeArtist1, 12

Es ware wirklich sinnvoll wie SalamiBrot1337 schon gesagt hat, den Code ein wenig zu verkürzen. Ich würde die auch raten das gesamte Program irgendwo bei pastebin etc hochzuladen und den Link nochmal zu posten.

So kann ich mir dein Problem genauer angucken und auch verbesserungsvorschläge geben.

Kommentar von LifeArtist1 ,

Außerdem ist dein Button nicht high; er hat eine height und eine width.

Antwort
von SalamiBrot1337, 11

Es wäre um sehr vieles effizienter und übersichtlicher wenn du das nicht Hardcoden, sondern mit einer Schleife lösen würdest.

Keine passende Antwort gefunden?

Fragen Sie die Community