a_jan2002 0 Newbie Poster

I have been working on connect five in python as a project. I have got this far but I cannot figure out how to make history of the things that have been clicked and how to undo. This is what i have got so far. I cannot make the player change either.

from Tkinter import *
import classgui

class Gomoku(Frame):
    def __init__(self, root):
        Frame.__init__(self, root)
        self.grid()
        self.setup_widgets()

    def setup_widgets(self):
        self.button_list = []
        for row_list in range(15):
            column1_gomoku=[]
            for col in range(15):
                button=Button(self, width=1)
                button.bind("<ButtonRelease-1>", self.button_click)
                button.grid(row = row_list, column = col)
                column1_gomoku.append(button)
            self.button_list.append(column1_gomoku)

        self.win_label=Label(self, text="")
        self.win_label.grid(row=16, column=0, columnspan=15)
        self.button_undo=Button(self, text="UNDO" )\
                          .grid(row=17, column=0, columnspan=5)
        
        self.new_game=Button(self, text="NEW GAME", command=self.game_new)\
                       .grid(row=17, column=5, columnspan=5)
        
        self.button_quit=Button(self, text="QUIT", command=self.quit_game)\
                          .grid(row=17, column=10, columnspan=5)
                      
    
            
    def button_click(self, event):
        turn = "O"
        game_over = False
        if not game_over:
            if turn == "O":
                event.widget.config(bg = "black")
                turn = "X"
            else:
                event.widget.config(bg = "white")
                turn = "O"
                

        for i in range(15):
            for j in range(15):
                if event.widget == self.button_list[i][j]:
                    result = self.game_logic.move(i, j)
                if result=="black":
                    event.widget.config(bg="black")
                elif result=="white":
                    event.widget.config(bg="white")
                elif result=="black win":
                    self.label=label(self, text="Player 1 Wins")
                elif result=="white win":
                    self.label=label(self, text="Player 2 Wins")
                else:
                    self.label.set("")
                    
                
        event.widget.config(bg = "black")
    #Toggle Player turn

    def game_new(self):
        command = self.setup_widgets()

    def quit_game(self):
        self.quit()
        
        
                

root=Tk()
game_frame = Gomoku(root)
root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.