Python スクリプトを実行しようとしたところ、無効な構文エラーが発生しました。問題を再確認しましたが、まだ問題を確認できません。問題を確認できる人はいますか? 以下は、誰かが問題を見るのを助けることができる場合のコードです。
ありがとう。
import random
import Tkinter
class life (Tkinter.Frame):
def __init__(self,x,y):
Tkinter.Frame.__init__(self)
self.master.title("The Game Of Life")
self.grid = [[False for j in range (y)] for i in range (x)]
universe = Tkinter.Frame(self)
def createButton (i,j):
bitmap=None
if self.grid[i][j]:bitmap ='gray75'
gridEntry = Tkinter.Button(universe, bitmap=bitmap)
gridEntry.grid(row=i, column =j)
self._applyToEachCellOfGrid (createButton)
universe.pack(side='top')
scale= Tkinter.Scale(self, orient = Tkinter.HORIZONTAL, from_=1, to =10,
command=self.setPeriod)
scale.pack(side='top')
quit=Tkinter.Button(self, text='Quit', command=self.quit)
quit.pack(side='left')
run=Tkinter.Button(self, text='Run' , command=self.run)
run.pack(side='right')
pause=Tkinter.Button(self, text='Pause', command=self.pause)
pause.pack(side='right')
self.pack()
def _applyToEachCellOfGrid (self, function) :
for i in range (len(self.grid)):
for j in range (len(self.grid[i])):
function(i,j)
def populateGridRandomly(self,x):
random.seed()
def setRandomly(i,j):
if random.random()<x:self.grid[i][j]= True
self._applyToEachCellOfGrid(setRandomly)
def calculateNextGeneration(self):
newGrid=[[ False for j in range ( len (self.grid[i]))] for i in range ( len (self.grid))]
def calculateLiveness(x,y):
count = 0
for i in range (x-1, x+2):
if 0 <=i<len (self.grid[i]):
if ((i !=x)or(j !=y)) and self.grid[i][j]:count +=1
if self.grid[x][y]:return 2 <= count <=3
else: return count ==3
def setNewGrid(x,y):
newGrid[x][y]= calculateLiveness(x,y)
self._applyToEachCellOfGrid (setNewGrid)
self.grid = newGrid
def pause(self):
print 'pause called.'
def run(self):
print 'run called'
def setPeriod (self, value):
print 'setPeriod called with value' , value
if __name__ =="__main__':
game=Life(8,10)
game.mainloop()