ttt/Tic Tac Toe.py

128 lines
4.1 KiB
Python

from tkinter import *
root = Tk()
root.geometry("900x500")
punkte = 0
punkte1 = 0
f1 = StringVar(value="1")
f2 = StringVar(value="2")
f3 = StringVar(value="3")
f4 = StringVar(value="4")
f5 = StringVar(value="5")
f6 = StringVar(value="6")
f7 = StringVar(value="7")
f8 = StringVar(value="8")
f9 = StringVar(value="9")
Label(root, textvariable=f1, font=("times", 25)).grid(row=2, column=1)
Label(root, textvariable=f2, font=("times", 25)).grid(row=2, column=2)
Label(root, textvariable=f3, font=("times", 25)).grid(row=2, column=3)
Label(root, textvariable=f4, font=("times", 25)).grid(row=3, column=1)
Label(root, textvariable=f5, font=("times", 25)).grid(row=3, column=2)
Label(root, textvariable=f6, font=("times", 25)).grid(row=3, column=3)
Label(root, textvariable=f7, font=("times", 25)).grid(row=4, column=1)
Label(root, textvariable=f8, font=("times", 25)).grid(row=4, column=2)
Label(root, textvariable=f9, font=("times", 25)).grid(row=4, column=3)
def reset():
f1.set(value="1")
f2.set(value="2")
f3.set(value="3")
f4.set(value="4")
f5.set(value="5")
f6.set(value="6")
f7.set(value="7")
f8.set(value="8")
f9.set(value="9")
Label(root, text=" ").grid(row=8, column=2)
def result():
if f1.get()==f2.get()==f3.get() == "O" or f1.get()==f5.get()==f9.get() == "O" or f1.get()==f4.get()==f7.get() == "O" or f4.get()==f5.get()==f6.get() == "O" or f7.get()==f8.get()==f9.get() == "O" or f2.get()==f5.get()==f8.get()== "O" or f3.get()==f6.get()==f9.get() == "O":
Label(root, text="Spieler 1 Gewinnt").grid(row=8, column=2)
Button(root, text="Neue Runde", command=reset).grid(row=9, column=2)
global punkte
punkte += 1
Label(root, text="Punkte:" ).grid(row=10, column=0)
Label(root, text=punkte).grid(row=11,column=0)
def result1():
if f1.get()==f2.get()==f3.get() == "X" or f1.get()==f5.get()==f9.get() == "X" or f1.get()==f4.get()==f7.get() == "X" or f4.get()==f5.get()==f6.get() == "X" or f7.get()==f8.get()==f9.get() == "X" or f2.get()==f5.get()==f8.get()== "X" or f3.get()==f6.get()==f9.get() == "X":
Label(root, text="Spieler 2 Gewinnt").grid(row=8, column=2)
Button(root, text="Neue Runde", command=reset).grid(row=9, column=2)
global punkte1
punkte1 += 1
Label(root, text="Punkte:" ).grid(row=10, column=7)
Label(root, text=punkte).grid(row=11,column=7)
def ok():
zug=zug_wert.get()
result
if zug == "1":
f1.set("O")
result()
elif zug == "2":
f2.set("O")
result()
elif zug == "3":
f3.set("O")
result()
elif zug == "4":
f4.set("O")
result()
elif zug == "5":
f5.set("O")
result()
elif zug == "6":
f6.set("O")
result()
elif zug == "7":
f7.set("O")
result()
elif zug == "8":
f8.set("O")
result()
elif zug == "9":
f9.set("O")
result()
def ok1():
zug1=zug1_wert.get()
if zug1 == "1":
f1.set("X")
result1()
elif zug1 == "2":
f2.set("X")
result1()
elif zug1 == "3":
f3.set("X")
result1()
elif zug1 == "4":
f4.set("X")
result1()
elif zug1 == "5":
f5.set("X")
result1()
elif zug1 == "6":
f6.set("X")
result1()
elif zug1 == "7":
f7.set("X")
result1()
elif zug1 == "8":
f8.set("X")
result1()
elif zug1 == "9":
f9.set("X")
result1()
Label(root, text="TIC TAC TOE", font=("times", 25)).grid(row=0, column=2)
Label(root, text="Spieler 1 ", font=("times", 25)).grid(row=1, column=0)
Label(root, text="Spieler 2 ", font=("times", 25)).grid(row=1, column=7)
zug_wert = Entry(root)
zug_wert.grid(column=0)
zug1_wert = Entry(root)
zug1_wert.grid(row=5,column=7)
Button(root, text="OK", command=ok).grid(column=0)
Button(root, text="Ok", command=ok1).grid(row=6, column=7)
root.mainloop()