gcfgxh

dhsfdgh

from tkinter import *               # графическая библиотека
from random import shuffle          # перемешать список suffle(A)

column = 5                          # столбцы
row = 5                             # строки
btn = []                            # список кнопок

def play(n):                        # функция обработчик нажатия на кнопку
    btn[n].config(text = n)

for i in range(row):
    f = Frame()
    f.pack(expand=YES, fill=BOTH)
    for j in range(column):
        btn += [Button(f, font =("mono", 16, "bold"), width = 5, height=3)]
        btn[-1].pack(expand=YES, fill=BOTH, side=LEFT)
        btn[-1].config(text = " ", command=lambda n=i*column+j:play(n))

mainloop()

Лист. 1.

Рис. 1.

dfhdfh

dthdfsghs

dfgh

dfgh

dfh

from tkinter import *               # графическая библиотека
from random import shuffle          # перемешать список suffle(A)

column = 5                          # столбцы
row = 5                             # строки
btn = []                            # список кнопок
playGround = [1,0,0,0,0] * (row*column//5 + 1)
shuffle(playGround)

def play(n):                        # функция обработчик нажатия на кнопку
    if playGround[n] == 1:
        btn[n].config(text = "M")
        return
    m = 0
    for i in [n-column, n, n+column]:
        for j in [-1, 0, 1]:
            m += playGround[i+j]
    btn[n].config(text = m)

for i in range(row):
    f = Frame()
    f.pack(expand=YES, fill=BOTH)
    for j in range(column):
        n=i*column+j
        btn += [Button(f, font =("mono", 16, "bold"), width = 5, height=3)]
        btn[-1].pack(expand=YES, fill=BOTH, side=LEFT)
        btn[-1].config(text = ' ', command=lambda n=n:play(n))

mainloop()

fzxsgth

fsghs

from tkinter import *               # графическая библиотека
from random import shuffle          # перемешать список suffle(A)

column = 5                          # столбцы
row = 5                             # строки
btn = []                            # список кнопок
playGround = [1,0,0,0,0] * (row*column//5 + 1)
shuffle(playGround)

def play(n):                        # функция
    if playGround[n] == 1:
        btn[n].config(text = "M")
        return
    m = 0
    for i in [n-column, n, n+column]:
        for j in [-1, 0, 1]:
            if i+j >= 0 and i+j < row*column:
                if i//column == (i+j)//column:
                    m += playGround[i+j]
    if m == 0:
        btn[n].config(text = " ", bg='grey')
    else:
        btn[n].config(text = m)

def flag(n):
    btn[n].config(text = "F")

for i in range(row):
    f = Frame()
    f.pack(expand=YES, fill=BOTH)
    for j in range(column):
        n=i*column+j
        btn += [Button(f, font =("mono", 16, "bold"), width = 1)]
        btn[-1].pack(expand=YES, fill=BOTH, side=LEFT)
        btn[-1].config(text = ' ', command=lambda n=n: play(n))
        btn[-1].bind('<Button-3>', lambda event, n=n: flag(n))

mainloop()

fgh

fgh

dfgh

dgfh

dfgh

fgsj

xfgjs