├── README.md └── Advance Tic Tac Toe.py /README.md: -------------------------------------------------------------------------------- 1 | # Advance-Tic-Tac-Toe 2 | Enjoy you game ...With Awsome scoring system and amazing GUI :) 3 | -------------------------------------------------------------------------------- /Advance Tic Tac Toe.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | import tkinter.messagebox 3 | 4 | root = Tk() 5 | root.geometry("1350x750+0+0") 6 | root.title("Tic Tac Toe") 7 | root.configure(background='mistyrose') 8 | Tops = Frame(root, bg='blue', pady=2, width=1350, height=100, relief=RIDGE) 9 | Tops.grid(row=0, column=0) 10 | flag = 0 11 | 12 | lblTitle = Label(Tops, font=('arial', 50, 'bold'), text=" Tic Tac Toe", bd=21, fg='dodgerblue', bg='mistyrose', 13 | justify=CENTER) 14 | lblTitle.grid(row=0, column=0) 15 | 16 | MainFrame = Frame(root, bg='#ffb84d', pady=2, width=1350, height=100, relief=RIDGE) 17 | MainFrame.grid(row=1, column=0) 18 | 19 | LeftFrame = Frame(MainFrame, bd=10, width=750, height=500, pady=2, padx=10, bg='#ffb84d', relief=RIDGE) 20 | LeftFrame.pack(side=LEFT) 21 | 22 | RightFrame = Frame(MainFrame, bd=10, width=750, height=500, padx=10, pady=2, bg='#ffb84d', relief=RIDGE) 23 | RightFrame.pack(side=RIGHT) 24 | 25 | RightFrame1 = Frame(RightFrame, bd=10, width=600, height=200, padx=10, pady=2, bg='#ffb84d', relief=RIDGE) 26 | RightFrame1.grid(row=0, column=0) 27 | 28 | RightFrame2 = Frame(RightFrame, bd=10, width=560, height=360, padx=10, pady=2, bg='#ffb84d', relief=RIDGE) 29 | RightFrame2.grid(row=1, column=0) 30 | 31 | PlayerX = IntVar() 32 | PlayerO = IntVar() 33 | 34 | PlayerX.set(0) 35 | PlayerO.set(0) 36 | Player1 = StringVar() 37 | Player2 = StringVar() 38 | pa = StringVar() 39 | pb = StringVar() 40 | 41 | buttons = StringVar() 42 | click = True 43 | 44 | 45 | def checker(buttons): 46 | global click 47 | if buttons["text"] == " " and click == True: 48 | buttons["text"] = "X" 49 | buttons.configure(background="white", fg='blue') 50 | click = False 51 | scorekeeper() 52 | elif buttons["text"] == " " and click == False: 53 | buttons["text"] = "O" 54 | buttons.configure(background="white", fg='red') 55 | click = True 56 | scorekeeper() 57 | 58 | 59 | def scorekeeper(): 60 | global pa, pb, Player1, Player2 61 | if (button1["text"] == "X" and button2["text"] == "X" and button3["text"] == "X"): 62 | button1.configure(background='#90ff0a') 63 | button2.configure(background='#90ff0a') 64 | button3.configure(background='#90ff0a') 65 | n = int(PlayerX.get()) 66 | score = (n + 1) 67 | PlayerX.set(score) 68 | pa = "Congratulations " + Player1.get() + " you have Won the Game!!" 69 | tkinter.messagebox.showinfo("Tic Tac Toe", pa) 70 | reset() 71 | if (button4["text"] == "X" and button5["text"] == "X" and button6["text"] == "X"): 72 | button4.configure(background='#90ff0a') 73 | button5.configure(background='#90ff0a') 74 | button6.configure(background='#90ff0a') 75 | n = int(PlayerX.get()) 76 | score = (n + 1) 77 | PlayerX.set(score) 78 | pa = "Congratulations " + Player1.get() + " you have Won the Game!!" 79 | tkinter.messagebox.showinfo("Tic Tac Toe", pa) 80 | reset() 81 | if (button7["text"] == "X" and button8["text"] == "X" and button9["text"] == "X"): 82 | button7.configure(background='#90ff0a') 83 | button8.configure(background='#90ff0a') 84 | button9.configure(background='#90ff0a') 85 | n = int(PlayerX.get()) 86 | score = (n + 1) 87 | PlayerX.set(score) 88 | pa = Player1.get() + " Won the Game!!" 89 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 90 | reset() 91 | if (button1["text"] == "X" and button4["text"] == "X" and button7["text"] == "X"): 92 | button1.configure(background='#90ff0a') 93 | button4.configure(background='#90ff0a') 94 | button7.configure(background='#90ff0a') 95 | n = int(PlayerX.get()) 96 | score = (n + 1) 97 | PlayerX.set(score) 98 | pa = Player1.get() + " Won the Game!!" 99 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 100 | reset() 101 | if (button5["text"] == "X" and button2["text"] == "X" and button8["text"] == "X"): 102 | button5.configure(background='#90ff0a') 103 | button2.configure(background='#90ff0a') 104 | button8.configure(background='#90ff0a') 105 | n = int(PlayerX.get()) 106 | score = (n + 1) 107 | PlayerX.set(score) 108 | pa = Player1.get() + " Won the Game!!" 109 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 110 | reset() 111 | if (button6["text"] == "X" and button9["text"] == "X" and button3["text"] == "X"): 112 | button6.configure(background='#90ff0a') 113 | button9.configure(background='#90ff0a') 114 | button3.configure(background='#90ff0a') 115 | n = int(PlayerX.get()) 116 | score = (n + 1) 117 | PlayerX.set(score) 118 | pa = Player1.get() + " Won the Game!!" 119 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 120 | reset() 121 | if (button1["text"] == "X" and button5["text"] == "X" and button9["text"] == "X"): 122 | button1.configure(background='#90ff0a') 123 | button5.configure(background='#90ff0a') 124 | button9.configure(background='#90ff0a') 125 | n = int(PlayerX.get()) 126 | score = (n + 1) 127 | PlayerX.set(score) 128 | pa = Player1.get() + " Won the Game!!" 129 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 130 | reset() 131 | if (button5["text"] == "X" and button7["text"] == "X" and button3["text"] == "X"): 132 | button5.configure(background='#90ff0a') 133 | button7.configure(background='#90ff0a') 134 | button3.configure(background='#90ff0a') 135 | n = int(PlayerX.get()) 136 | score = (n + 1) 137 | PlayerX.set(score) 138 | pa = Player1.get() + " Won the Game!!" 139 | tkinter.messagebox.showinfo(" Tic Tac Toe", pa) 140 | reset() 141 | # for O 142 | if (button1["text"] == "O" and button2["text"] == "O" and button3["text"] == "O"): 143 | button1.configure(background='#90ff0a') 144 | button2.configure(background='#90ff0a') 145 | button3.configure(background='#90ff0a') 146 | n = int(PlayerO.get()) 147 | score = (n + 1) 148 | PlayerO.set(score) 149 | pb = Player2.get() + " Won the Game!!" 150 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 151 | reset() 152 | if (button4["text"] == "O" and button5["text"] == "O" and button6["text"] == "O"): 153 | button4.configure(background='#90ff0a') 154 | button5.configure(background='#90ff0a') 155 | button6.configure(background='#90ff0a') 156 | n = int(PlayerO.get()) 157 | score = (n + 1) 158 | PlayerO.set(score) 159 | pb = Player2.get() + " Won the Game!!" 160 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 161 | reset() 162 | if (button7["text"] == "O" and button8["text"] == "O" and button9["text"] == "O"): 163 | button7.configure(background='#90ff0a') 164 | button8.configure(background='#90ff0a') 165 | button9.configure(background='#90ff0a') 166 | n = int(PlayerO.get()) 167 | score = (n + 1) 168 | PlayerO.set(score) 169 | pb = Player2.get() + " Won the Game!!" 170 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 171 | reset() 172 | if (button1["text"] == "O" and button4["text"] == "O" and button7["text"] == "O"): 173 | button1.configure(background='#90ff0a') 174 | button4.configure(background='#90ff0a') 175 | button7.configure(background='#90ff0a') 176 | n = int(PlayerO.get()) 177 | score = (n + 1) 178 | PlayerO.set(score) 179 | pb = Player2.get() + " Won the Game!!" 180 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 181 | reset() 182 | if (button5["text"] == "O" and button2["text"] == "O" and button8["text"] == "O"): 183 | button5.configure(background='#90ff0a') 184 | button2.configure(background='#90ff0a') 185 | button8.configure(background='#90ff0a') 186 | n = int(PlayerO.get()) 187 | score = (n + 1) 188 | PlayerO.set(score) 189 | pb = Player2.get() + " Won the Game!!" 190 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 191 | reset() 192 | if (button6["text"] == "O" and button9["text"] == "O" and button3["text"] == "O"): 193 | button9.configure(background='#90ff0a') 194 | button6.configure(background='#90ff0a') 195 | button3.configure(background='#90ff0a') 196 | n = int(PlayerO.get()) 197 | score = (n + 1) 198 | PlayerO.set(score) 199 | pb = Player2.get() + " Won the Game!!" 200 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 201 | reset() 202 | if (button1["text"] == "O" and button5["text"] == "O" and button9["text"] == "O"): 203 | button1.configure(background='#90ff0a') 204 | button5.configure(background='#90ff0a') 205 | button9.configure(background='#90ff0a') 206 | n = int(PlayerO.get()) 207 | score = (n + 1) 208 | PlayerO.set(score) 209 | pb = Player2.get() + " Won the Game!!" 210 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 211 | reset() 212 | if (button5["text"] == "O" and button7["text"] == "O" and button3["text"] == "O"): 213 | button3.configure(background='#90ff0a') 214 | button5.configure(background='#90ff0a') 215 | button7.configure(background='#90ff0a') 216 | n = int(PlayerO.get()) 217 | score = (n + 1) 218 | PlayerO.set(score) 219 | pb = Player2.get() + " Won the Game!!" 220 | tkinter.messagebox.showinfo(" Tic Tac Toe", pb) 221 | reset() 222 | 223 | 224 | def reset(): 225 | button1["text"] = " " 226 | button2["text"] = " " 227 | button3["text"] = " " 228 | button4["text"] = " " 229 | button5["text"] = " " 230 | button6["text"] = " " 231 | button7["text"] = " " 232 | button8["text"] = " " 233 | button9["text"] = " " 234 | 235 | button1.configure(background='white') 236 | button2.configure(background='white') 237 | button3.configure(background='white') 238 | button4.configure(background='white') 239 | button5.configure(background='white') 240 | button6.configure(background='white') 241 | button7.configure(background='white') 242 | button8.configure(background='white') 243 | button9.configure(background='white') 244 | 245 | 246 | def Newgame(): 247 | global pa, pb, Player1, Player2 248 | reset() 249 | PlayerX.set(0) 250 | PlayerO.set(0) 251 | Player1 = StringVar() 252 | Player2 = StringVar() 253 | 254 | nmPlayerX = Entry(RightFrame1, font=('arial', 40, 'bold'), bd=3, fg="black", textvariable=Player1, width=7, 255 | justify=LEFT).grid(row=0, column=1) 256 | nmPlayerO = Entry(RightFrame1, font=('arial', 40, 'bold'), bd=3, fg="black", textvariable=Player2, width=7, 257 | justify=LEFT).grid(row=1, column=1) 258 | 259 | 260 | lblPlayerX = Label(RightFrame1, font=('arial', 40, 'bold'), text="Player X :", padx=2, pady=2, bg="yellow", fg="black") 261 | lblPlayerX.grid(row=0, column=0, sticky=W) 262 | 263 | nmPlayerX = Entry(RightFrame1, font=('arial', 40, 'bold'), bd=3, fg="black", textvariable=Player1, width=7, 264 | justify=LEFT).grid(row=0, column=1) 265 | 266 | txtPlayerX = Button(RightFrame1, font=('arial', 26, 'bold'), bd=2, fg="black", bg="yellow", textvariable=PlayerX, 267 | width=4, 268 | justify=LEFT).grid(row=0, column=2) 269 | 270 | lblPlayerO = Label(RightFrame1, font=('arial', 40, 'bold'), text="Player O :", padx=2, pady=2, bg="yellow", fg="black") 271 | lblPlayerO.grid(row=1, column=0, sticky=W) 272 | 273 | nmPlayerO = Entry(RightFrame1, font=('arial', 40, 'bold'), bd=3, fg="black", textvariable=Player2, width=7, 274 | justify=LEFT).grid(row=1, column=1) 275 | 276 | txtPlayerO = Button(RightFrame1, font=('arial', 26, 'bold'), bd=2, fg="black", bg="yellow", textvariable=PlayerO, 277 | width=4, 278 | justify=LEFT).grid(row=1, column=2) 279 | 280 | btnReset = Button(RightFrame2, text="Reset", font=('arial', 40, 'bold'), height=1, width=15, fg='white', bg='dodgerblue', 281 | command=reset) 282 | btnReset.grid(row=1, column=0, padx=1, pady=11) 283 | 284 | btnNewGame = Button(RightFrame2, text="New Game", font=('arial', 40, 'bold'), height=1, width=15, fg='white', 285 | bg='dodgerblue', command=Newgame) 286 | btnNewGame.grid(row=2, column=0, padx=1, pady=11) 287 | 288 | button1 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 289 | command=lambda: checker(button1)) 290 | button1.grid(row=1, column=0, sticky=S + N + E + W) 291 | 292 | button2 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 293 | command=lambda: checker(button2)) 294 | button2.grid(row=1, column=1, sticky=S + N + E + W) 295 | 296 | button3 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 297 | command=lambda: checker(button3)) 298 | button3.grid(row=1, column=2, sticky=S + N + E + W) 299 | 300 | button4 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 301 | command=lambda: checker(button4)) 302 | button4.grid(row=2, column=0, sticky=S + N + E + W) 303 | 304 | button5 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 305 | command=lambda: checker(button5)) 306 | button5.grid(row=2, column=1, sticky=S + N + E + W) 307 | 308 | button6 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 309 | command=lambda: checker(button6)) 310 | button6.grid(row=2, column=2, sticky=S + N + E + W) 311 | 312 | button7 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 313 | command=lambda: checker(button7)) 314 | button7.grid(row=3, column=0, sticky=S + N + E + W) 315 | 316 | button8 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 317 | command=lambda: checker(button8)) 318 | button8.grid(row=3, column=1, sticky=S + N + E + W) 319 | 320 | button9 = Button(LeftFrame, text=" ", font=('arial', 30, 'bold'), height=3, width=8, bg='white', 321 | command=lambda: checker(button9)) 322 | button9.grid(row=3, column=2, sticky=S + N + E + W) 323 | 324 | root.mainloop() 325 | --------------------------------------------------------------------------------