Skip to content
Snippets Groups Projects
Commit 714726e4 authored by Dolleans Geoffrey's avatar Dolleans Geoffrey
Browse files

tkinter 1/many

parent b8184db2
No related branches found
No related tags found
No related merge requests found
from tkinter import *
from game_of_life.generate_universe import *
from game_of_life.generation import *
from game_of_life.survival import *
fenetre = Tk()
game_of_life = Toplevel(fenetre)
......@@ -10,21 +11,36 @@ canvas = Canvas(game_of_life)
canvas.pack()
def create_a_grid():
"create the grid for the graphic interface"
"""create the grid for the graphic interface"""
width = game_of_life.winfo_width()
heigth = game_of_life.winfo_height()
global zones #contient l'ensemble des zones representant des cellules
zones = []
for x in range(len(universe)):
zones.append([])
for y in range (len(universe[0])):
zones[x].append((x*width/100,(x+1)*width/100,y*width/100,(y+1)*width/100))
for x in range(len(universe)):
for y in range(len(universe[0])):
if universe[x][y]==1:
canvas.create_rectangle(zones[x][y],fill="black")
zones.append(canvas.create_rectangle(x*width/100,(x+1)*width/100,y*width/100,(y+1)*width/100), fill="black")
else:
zones.append(canvas.create_rectangle(x*width/100,(x+1)*width/100,y*width/100,(y+1)*width/100, fill="white"))
def update_grid():
"""mets la grille a jours """
for x in range(len(universe)):
for y in range (len(universe[0])):
if universe[x][y] == 0:
if naissance([x][y]) == 1:
"colorier la case zones[x][y] en vert"
else:
canvas.create_rectangle(zones[x][y],fill="white")
if survival(universe[x][y]) == 0:
"colorier la case zones[x][y] en rouge"
universe = generation(universe)
def create_cell_on_click(event):
"""créer une cellule vivante la ou l'utilisateur clique"""
x = event.x//(width/100)
y = event.y//(heigth/100)
universe[x][y] = 1
create_a_grid()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment