from numpy import array
from Tkinter import *
dimension = 100
root = Tk() # окно
root.title('Игра "Жизнь"')
frame1=Frame(root,width=1000,height=1000,bg='white',bd=1)
frame2=Frame(root, width=100,bg='gray',bd=1)
area = array([[0]*dimension]*dimension)
lst = []
def action(x, y):
if area[y][x] == 0:
area[y][x] = 1
else:
area[y][x] = 0
for x in range(len(area)):
for y in range(len(area[x])):
b = Button(frame1, text="", bg = 'blue', command = action(x, y))
b.grid(column = x, row = dimension - y)
lst.append((b, (x, y)))
frame1.pack(side='left')
frame2.pack(side='right')
def game(area):
born = []
die = []
for y in range(1, len(area)-1):
for x in range(1, len(area[y])-1):
if area[y][x] == 1:
if not survive(x, y):
die.append((x, y))
elif area[y][x] == 0:
if appear(x, y):
born.append((x, y))
for i in born:
area[i[1]][i[0]] = 1
for i in die:
area[i[1]][i[0]] = 0
def surrounding(x, y):
horiz = area[y][x-1] + area[y][x+1]
vert = area[y-1][x] + area[y+1][x]
diag = area[y-1][x-1] + area[y-1][x+1] + area[y+1][x+1] + area[y+1][x-1]
return vert + horiz + diag
def survive(x, y):
if surrounding(x, y) <= 1:
return False
elif surrounding(x, y) >= 4:
return False
else:
return True
def appear(x, y):
if surrounding(x, y) == 3:
return True
else:
return False
#for n in range(10):
# for i in range(len(area)):
# print i, area[i]
# print ' 0 1 2 3 4 5 6 7 8 9'
# print '-'*23
# game(area)
root.mainloop()
print area