-
Notifications
You must be signed in to change notification settings - Fork 1
/
tictactoe
81 lines (63 loc) · 3.59 KB
/
tictactoe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Written By : Joseph Zanini
from tkinter import *
import tkinter.messagebox
root = Tk()
root.title("Tic-Tac-Toe")
click = True
def winCheck():
if (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("Winner X", "You have just 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
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("Winner O", "You have just won the game")
def clicker(buttons):
global click
if buttons["text"] == " " and click == True:
buttons["text"] = "X"
click = False
winCheck()
elif buttons["text"] == " " and click == False:
buttons["text"] = "O"
click = True
winCheck()
button1 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button1))
button1.grid(row=1, column=0, sticky=S + N + E + W)
button2 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button2))
button2.grid(row=1, column=1, sticky=S + N + E + W)
button3 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button3))
button3.grid(row=1, column=2, sticky=S + N + E + W)
button4 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button4))
button4.grid(row=2, column=0, sticky=S + N + E + W)
button5 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button5))
button5.grid(row=2, column=1, sticky=S + N + E + W)
button6 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button6))
button6.grid(row=2, column=2, sticky=S + N + E + W)
button7 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button7))
button7.grid(row=3, column=0, sticky=S + N + E + W)
button8 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=8,
command=lambda: clicker(button8))
button8.grid(row=3, column=1, sticky=S + N + E + W)
button9 = Button(root, text=" ", font=('Times 26 bold'), height=4, width=4,
command=lambda: clicker(button9))
button9.grid(row=3, column=2, sticky=S + N + E + W)
root.mainloop()