-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.py
42 lines (29 loc) · 867 Bytes
/
Cell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
#
# Cell.py
from Tkinter import Button
from CellModel import CellModel
class Cell(Button, CellModel):
def __init__(self, master, index, callback=None):
Button.__init__(self, master)
CellModel.__init__(self, index)
# register a callback
self.callback = callback
self.config(command=self.clicked)
self.refresh()
def set_model(self, model):
self.alive = model.alive
self.refresh()
def model(self):
new_model = CellModel(self.index)
new_model.alive = self.alive
return new_model
def refresh(self):
color = "gray"
if self.alive: color = "green"
self.config(bg=color)
def clicked(self):
self.alive = not (self.alive)
self.refresh()
if self.callback != None:
self.callback()