五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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)的評論 (共 條)

分享到微博請遵守國家法律
六安市| 黄冈市| 德令哈市| 长武县| 三原县| 德格县| 儋州市| 花垣县| 高阳县| 南康市| 屯留县| 高台县| 永平县| 江门市| 江西省| 鸡东县| 五寨县| 鄂州市| 陆川县| 铜陵市| 长海县| 平定县| 汉中市| 衡阳市| 长顺县| 尤溪县| 荣昌县| 鸡西市| 黎川县| 霍城县| 彭山县| 瓦房店市| 佛坪县| 泰宁县| 平舆县| 开鲁县| 海丰县| 甘孜| 乐平市| 天柱县| 福清市|