-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathtic_tac_double.py
113 lines (96 loc) · 4.64 KB
/
tic_tac_double.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from tkinter import *
import tkinter.messagebox
import tkinter
root = tkinter.Tk()
root.title("..... TiC _ TaC _ Toe .....")
root.geometry("500x500")
count=0
turn='x'
def print(event):
global count
global turn
if turn=='x':
event["text"]='X'
turn = 'y'
elif turn=='y':
event["text"]='0'
turn='x'
count=count+1
win()
def clearboard():
global count
button1["text"]=''
button2["text"]=''
button3["text"]=''
button4["text"]=''
button5["text"]=''
button6["text"]=''
button7["text"]=''
button8["text"]=''
button9["text"]=''
count=0
def win():
isgameover=True
if button1["text"]=='X' and button2["text"]=='X' and button3["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button1["text"]=='0' and button2["text"]=='0' and button3["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button4["text"]=='X' and button5["text"]=='X' and button6["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button4=='0' and button5["text"]=='0' and button6["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button7["text"]=='X' and button8["text"]=='X' and button9["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button7["text"]=='0' and button8["text"]=='0' and button9["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button1["text"]=='X' and button4["text"]=='X' and button7["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button1["text"]=='0' and button4["text"]=='0' and button7["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button2["text"]=='X' and button5["text"]=='X' and button8["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button2["text"]=='0' and button5["text"]=='0' and button8["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button3["text"]=='X' and button6["text"]=='X' and button9["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button3["text"]=='0' and button6["text"]=='0' and button9["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button1["text"]=='X' and button5["text"]=='X' and button9["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button1["text"]=='0' and button5["text"]=='0' and button9["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif button3["text"]=='X' and button5["text"]=='X' and button7["text"]=='X':
tkinter.messagebox.showinfo("Result","Player 'X' win")
elif button3["text"]=='0' and button5["text"]=='0' and button7["text"]=='0':
tkinter.messagebox.showinfo("Result","Player 'Y' win")
elif count==9:
tkinter.messagebox.showinfo("Result","Match is Tie")
else:
isgameover=False
if isgameover==True:
clearboard()
lab1= Label(root,bg='yellow',text="THIS IS A TiC_TaC_Toe Game ",height=1)
lab1.grid(row=0)
lab2=Label(root,bg='yellow',text="player x = 'X'",font=20)
lab2.grid(row=1,column=2)
lab3=Label(root,bg='yellow',text="player Y = '0'",font=20)
lab3.grid(row=2,column=2)
button1=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button1))
button1.grid(row=3,column=1)
button2=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button2))
button2.grid(row=3,column=2)
button3=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button3))
button3.grid(row=3,column=3)
button4=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button4))
button4.grid(row=4, column=1)
button5=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button5))
button5.grid(row=4, column=2)
button6=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button6))
button6.grid(row=4, column=3)
button7=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button7))
button7.grid(row=5, column=1)
button8=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button8))
button8.grid(row=5, column=2)
button9=Button(root,text='',bg='green',width=4,height=2,font=("Arial",30),command=lambda:print(button9))
button9.grid(row=5, column=3)
root.mainloop()