Yes. I decided to take a different approach which works.
To show what I am working on I'll post the code.
#! /usr/bin/env python3
'''tkinter tic tac toe'''
import tkinter as tk
import random as rnd
from time import sleep
class Game:
def __init__(self, parent):
# Set the parent
self.parent = parent
# Storage for entries
self.entries = []
# Grid cordinates
self.grid_cords = [
(0,0), (0,1), (0,2),
(1,0), (1,1), (1,2),
(2,0), (2,1), (2,2)
]
for i in range(3):
for j in range(3):
self.frame = tk.Frame(self.parent, borderwidth=1, relief='solid', \
cursor='hand2', width=100, height=100)
self.frame.grid(column=i, row=j)
self.frame.bind('<Button-1>', self.get_cords)
def do_entries(self, text,col,row, fg='red'):
label = tk.Label(self.parent, fg=fg, text=text, font=('serif', 60))
label.grid(column=col, row=row)
self.entries.append(label)
def get_cords(self, event):
x_cord = event.x_root - self.parent.winfo_rootx()
y_cord = event.y_root - self.parent.winfo_rooty()
loc = self.parent.grid_location(x_cord, y_cord)
self.do_entries('X',loc[0],loc[1])
self.grid_cords.remove(loc)
self.computer()
def computer(self):
pick = rnd.choice(self.grid_cords)
self.grid_cords.remove(pick)
self.do_entries('O',pick[0], pick[1],fg='blue')
root = tk.Tk()
Game(root)
root.mainloop()