国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

python模塊調(diào)用練習(I)

2020-03-25 16:47 作者:一心想當網(wǎng)紅的李老師  | 我要投稿

還是兩個不同文件種模塊調(diào)用的問題。

1、算法模塊。model.py

height=100

width=100


grid_model=[0]*height

next_grid_model=[0]*height

for i in range(height):

? ? grid_model[i]=[0]*width

? ? next_grid_model[i]=[0]*width

? ??

def next_gen():

? ? global grid_model,next_grid_model

? ??

? ? for i in range(0,height):

? ? ? ? for j in range (0,width):

? ? ? ? ? ? cell=0

? ? ? ? ? ? print('check cell',i,j)

? ? ? ? ? ? count=count_neighbours(grid_model,i,j)

? ? ? ? ? ??

? ? ? ? ? ? if grid_model[i][j]==0:

? ? ? ? ? ? ? ? if count==3:

? ? ? ? ? ? ? ? ? ? cell=1

? ? ? ? ? ? elif grid_model[i][j]==1:

? ? ? ? ? ? ? ? if count==2 or count==3:

? ? ? ? ? ? ? ? ? ? cell=1

? ? ? ? ? ? next_grid_model[i][j]=cell


temp=grid_model

grid_model=next_grid_model

next_grid_model=temp

? ? ? ? ? ? ? ??

def count_neighbours(grid,row,col):

? ? count=0

? ? if (row-1>=0):

? ? ? ? count=count+grid[row-1][col]

? ? if (row-1>=0) and (col-1>=0):

? ? ? ? count=count+grid[row-1][col-1]

? ? if (row-1>=0) and (col+1<width):

? ? ? ? count=count+grid[row-1][col+1]

? ? if (col-1>=0):

? ? ? ? count=count+grid[row][col-1]

? ? if ?(col+1<width):

? ? ? ? count=count+grid[row][col+1]

? ? if (row+1<height):

? ? ? ? count=count+grid[row+1][col]

? ? if (row+1<height) and (col-1>=0):

? ? ? ? count=count+grid[row+1][col-1]

? ? if (row+1<height) and (col+1<width):

? ? ? ? count=count+grid[row+1][col+1]

? ? return count

?

if __name__=='__main__':

? ? next_gen()


2、視窗文件。view.py

from tkinter import *

import model


cell_size=5



def setup():

? ? global root,grid_view,cell_size,start_btn,clear_btn,choice

? ??

? ? root=Tk()

? ? root.title('game screen')

? ? grid_view=Canvas(root,width=model.width*cell_size, ?

? ? ? ? ? ? ? ? ? ? ?height=model.height*cell_size,

? ? ? ? ? ? ? ? ? ? ?borderwidth=0,

? ? ? ? ? ? ? ? ? ? ?bg='white')

####這個部分開始引用model里面的信息

? ? start_btn=Button(root,text="start",width=12)

? ? clear_btn=Button(root,text="clear",width=12)

? ? choice=StringVar(root)

? ? choice.set('choose a pattern')

? ? option=OptionMenu(root,choice,"'choose a pattern","grider","grider gun","random")

? ? option.config(width=25)

? ? ####學習了怎么設置選擇項

? ? grid_view.pack()

? ? start_btn.pack()

? ? clear_btn.pack()

? ? option.pack()


if __name__=='__main__':

? ? setup()

? ? mainloop()

雖然沒有顯示怎么實現(xiàn)功能,但是調(diào)用成功。

####第一次根據(jù)書本嘗試。

python模塊調(diào)用練習(I)的評論 (共 條)

分享到微博請遵守國家法律
图木舒克市| 隆安县| 原阳县| 关岭| 来宾市| 射阳县| 子长县| 石狮市| 华宁县| 阿城市| 舞钢市| 承德县| 即墨市| 罗源县| 佳木斯市| 白城市| 集安市| 囊谦县| 大庆市| 恭城| 阳泉市| 东兰县| 石泉县| 金堂县| 马龙县| 开江县| 安康市| 苍山县| 郯城县| 景宁| 民和| 河东区| 屯门区| 夏津县| 轮台县| 什邡市| 乐至县| 尤溪县| 望谟县| 垦利县| 南阳市|