import tkinter as tk
import random as r

win = tk.Tk()
win.geometry("522x625")
canv = tk.Canvas(win, width=500, height=500, bg="light green")
canv.grid(row=0, column=0)

info_label = tk.Label(win, text="Информация о клетке", font=("Arial", 16))
info_label.grid(row=1, column=0) 

class Cell:
    def __init__(self, x, y, army):
        self.x = x
        self.y = y
        self.army = army
        self.button = None
    
    def change_army(self, num):
        self.army = num
        
    def go_to_cell_army(self):
        prev_button.army += self.army
        self.army = 0
    
    def paint_cell(self):
        self.button = tk.Button(canv, text=self.army, command=self.click, width=6, height=3, bg="white", relief="flat")
        self.button.grid(row=self.x, column=self.y)    
    
    def click(self):
        global prev_button, prev_prev_button
        if prev_prev_button:
            prev_prev_button.config(bg="white")
        if prev_button:
            prev_prev_button = prev_button 
            prev_prev_button.config(bg="gray") 
        self.button.config(bg="gray")
        prev_button = self.button
        info_label.config(text=f"Координаты клетки: ({self.x+1}, {self.y+1})\nАрмия: {self.army}")

prev_button = None
prev_prev_button = None

for i in range(10):
    for j in range(10):
        cell = Cell(i, j, army=r.randint(1, 5))
        cell.paint_cell()

goto_button = tk.Button(win, text="Переместить армию", font=("Arial", 16), command=go_to_cell_army)
goto_button.grid(row=2, column=0)


win.mainloop()
