from tkinter import *
from examplegame import *
from tkinter import messagebox
class gameInterface:

    def __init__(self,wnd):
        self.game = theGame()
        self.buttons = []
        for i in range(9):
            b = Button(wnd,text=" ",width=20,height=10,command=lambda x=i+1:self.buttonPressed(x))
            self.buttons.append(b)
            b.grid(row=i//3, column = i%3)
    def buttonPressed(self,x):
        if self.game.getResult() == 0:
            if self.game.isValidMove(x):
                self.game.makeMove(x)
                self.buttons[x-1].configure(text=self.game.getPlayerSymbol())
                self.game.switchPlayers()

        if self.game.getResult() == 1:
            
            messagebox.showinfo("Result","You Won")
            self.game = theGame()
            
wnd = Tk()
app = gameInterface(wnd)
wnd.mainloop()
