I am new to Python, and I am working on a Tic Tac Toe game coded using OOP. After completing the tile, however, I cannot figure out how to determine the winner (or draw). Here is the code:
import tkinter as tk
root =tk.Tk()
root.title('Tic Tac Toe')
player = 'cross'
class Tile():
def __init__(self):
self.tile = tk.Button(
root,
font = ('Arial', 35),
width=3,
command = self.write
)
def write(self):
global player
if player == 'cross':
self.tile.config(text = 'X', state = tk.DISABLED)
player = 'circle'
elif player == 'circle':
self.tile.config(text = 'O', state = tk.DISABLED)
player = 'cross'
else:
print('wrong var')
def grid(self, row, column):
self.tile.grid(row=row, column=column)
for row in range(0,3):
for column in range(0,3):
Tile().grid(row, column)
root.mainloop()
I wonder if I can assign a name to each of the tile objects, so that I can call them later and get the button text of each of them, hence compare them with the win conditions.