Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么价值观会变成“无”而不是“活”?_Python_Tkinter - Fatal编程技术网

Python 为什么价值观会变成“无”而不是“活”?

Python 为什么价值观会变成“无”而不是“活”?,python,tkinter,Python,Tkinter,这是人生游戏节目。当我测试它时,我的surroundingrow,col函数返回0,即使配置文件指示8个方块将被激活。只需在打开配置文件后打印电路板就可以进行测试,结果显示,不是让指示的方块显示“LIVE”,而是让“LIVE”方块显示“None”,这样就不会计算“LIVE”值 [[None,None,None,0,0,0],[None,0,0,0,0],[None,None,None,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,

这是人生游戏节目。当我测试它时,我的surroundingrow,col函数返回0,即使配置文件指示8个方块将被激活。只需在打开配置文件后打印电路板就可以进行测试,结果显示,不是让指示的方块显示“LIVE”,而是让“LIVE”方块显示“None”,这样就不会计算“LIVE”值

[[None,None,None,0,0,0],[None,0,0,0,0],[None,None,None,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]是我在印刷电路板时得到的。看不到我在这里遗漏了什么

LIVE = 1
DEAD = 0

def board(canvas, width, height, n):
    for row in range(n+1):
        for col in range(n+1):
            canvas.create_rectangle(row*height/n,col*width/n,(row+1)*height/n,(col+1)*width/n,width=1,fill='black',outline='green')                      

n = int(raw_input("Enter the dimensions of the board: "))
width = n*25
height = n*25

from Tkinter import *
import math

window=Tk()
window.title('Game of Life')

canvas=Canvas(window,width=width,height=height,highlightthickness=0)
canvas.grid(row=0,column=0,columnspan=5)

board = [[DEAD for row in range(n)] for col in range(n)]

rect = [[None for row in range(n)] for col in range(n)]


for row in range(n):
    for col in range(n):      
        rect[row][col] = canvas.create_rectangle(row*height/n,col*width/n,(row+1)*height/n,(col+1)*width/n,width=1,fill='black',outline='green') 

#canvas.itemconfigure(rect[2][3], fill='red') #rect[2][3] is rectangle ID

#print rect

f = open('filename','r') #filename is whatever configuration file is chosen that gives the step() function to work off of for the first time
for line in f:
    parsed = line.split()
    print parsed
    if len(parsed)>1:
        row = int(parsed[0].strip())
        col = int(parsed[1].strip())
        board[row][col] = LIVE
        board[row][col] = canvas.itemconfigure(rlist[row][col], fill='red')        

def surrounding(row,col):
    count = 0
    if board[(row-1) % n][(col-1) % n] == LIVE:
        count += 1
    if board[(row-1) % n][col % n] == LIVE:
        count += 1
    if board[(row-1) % n][(col+1) % n] == LIVE:
        count += 1
    if board[row % n][(col-1) % n] == LIVE:
        count += 1
    if board[row % n][(col+1) % n] == LIVE:
        count += 1
    if board[(row+1) % n][(col-1) % n] == LIVE:
        count +=1
    if board[(row+1) % n ][col % n] == LIVE:
        count += 1
    if board[(row+1) % n][(col+1) % n] == LIVE:
        count += 1
    print count
    return count

surrounding(1,1)

您将两次分配给板嵌套列表中的项目:

    board[row][col] = LIVE
    board[row][col] = canvas.itemconfigure(rlist[row][col], fill='red')
第一个将1指定给适当的值,第二个将1替换为None,因为这是使用这些参数调用canvas.itemconfigure时的返回值。我怀疑在不测试它的情况下,您应该简单地从第二个语句中删除赋值:

    board[row][col] = LIVE
    canvas.itemconfigure(rlist[row][col], fill='red')

这可能仍然存在一些问题,例如rlist可能需要是rect,但应该解决无值的问题。

您将两次分配给板嵌套列表中的项目:

    board[row][col] = LIVE
    board[row][col] = canvas.itemconfigure(rlist[row][col], fill='red')
第一个将1指定给适当的值,第二个将1替换为None,因为这是使用这些参数调用canvas.itemconfigure时的返回值。我怀疑在不测试它的情况下,您应该简单地从第二个语句中删除赋值:

    board[row][col] = LIVE
    canvas.itemconfigure(rlist[row][col], fill='red')
这可能仍然存在一些问题,例如rlist可能需要是rect,但是应该解决没有值的问题