python - On tkinter, how to determine which of buttons were clicked? -


i'm making big tic-tac-toe game. whenever button pressed, want class gameplay check whether there amount n of same marks in row (=win). can't figure out how tell class gameplay if method move() activated in class box.

sorry, i'm starter. here's code.

from tkinter import *  # grid maxsize = 30*30   def game():     n = [0]     marks = ["x", "o"]     points = [0,0]     boxes = []       class box:         def __init__(self, window, x, y):             self.__x = x             self.__y = y             self.__state = ""             self.__button = button(window, text = self.__state, command = self.move, height = 1, width = 2)         def move(self):             if self.__state == "":                 self.__state = marks[n[0]]                 n[0] = (n[0]+1)%2                 self.__button.config(text = self.__state)          def grid(self, **kwargs):             self.__button.grid(**kwargs)         def state(self):             return self.__state      class gameplay:         def __init__(self, size, towin):             self.__mainwindow = tk()             self.__mainwindow.resizable(width=false, height=false)             self.__mainlabel = label(self.__mainwindow, text = "se, joka saa " + str(towin) + " peräkkäin ensimmäisenä, voittaa!")             self.__mainlabel.grid(row = 0, column = 0, columnspan = size)             boxes = []             y in range(size):                 boxes.append([])                 x in range(size):                     boxes[y].append(box(self.__mainwindow, x, y))                     boxes[y][x].grid(row=y+1, column=x)             self.__mainwindow.mainloop()          playgame = gameplay(20, 4)  game() 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -