Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coding Week Gol Dolleans Boujerfaoui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boujerfaoui Yassine
Coding Week Gol Dolleans Boujerfaoui
Commits
8b49de03
Commit
8b49de03
authored
6 years ago
by
Boujerfaoui Yassine
Browse files
Options
Downloads
Plain Diff
Problème de fonctionnement de AffichageTkinter
parents
1edf76cc
a382ae7b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game_of_life/AffichageTkinter.py
+90
-0
90 additions, 0 deletions
game_of_life/AffichageTkinter.py
with
90 additions
and
0 deletions
game_of_life/AffichageTkinter.py
0 → 100644
+
90
−
0
View file @
8b49de03
from
tkinter
import
*
from
game_of_life.generate_universe
import
*
from
game_of_life.generation
import
*
from
game_of_life.survival
import
*
from
game_of_life.add_seed
import
*
from
game_of_life.Affichage_universe
import
*
import
random
as
rd
fenetre
=
Tk
()
game_of_life
=
Toplevel
(
fenetre
,
width
=
1000
,
height
=
1000
)
game_of_life
.
grid
()
canvas
=
Canvas
(
game_of_life
)
canvas
.
pack
()
var_text
=
StringVar
ligne_texte
=
Entry
(
fenetre
,
textvariable
=
var_text
,
width
=
30
)
ligne_texte
.
pack
()
def
create_a_grid
():
"""
create the grid for the graphic interface
"""
global
universe
print
(
"
création de la grille
"
)
universe
=
generate_universe
((
100
,
100
))
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
])):
if
universe
[
x
][
y
]
==
1
:
zones
[
x
].
append
(
canvas
.
create_rectangle
(
x
*
10
,
y
*
10
,(
x
+
1
)
*
10
,(
y
+
1
)
*
10
),
fill
=
"
black
"
)
else
:
zones
[
x
].
append
(
canvas
.
create_rectangle
(
x
*
10
,
y
*
10
,(
x
+
1
)
*
10
,(
y
+
1
)
*
10
,
fill
=
"
white
"
))
def
update_grid
():
"""
met la grille à jour
"""
global
universe
for
x
in
range
(
len
(
universe
)):
for
y
in
range
(
len
(
universe
[
0
])):
if
universe
[
x
][
y
]
==
0
:
if
naissance
(
universe
,(
x
,
y
))
==
1
:
"
colorier la case zones[x][y] en vert
"
canvas
.
itemconfig
(
zones
[
x
][
y
],
fill
=
"
green
"
)
else
:
"
colorier la case zones[x][y] en banc
"
canvas
.
itemconfig
(
zones
[
x
][
y
],
fill
=
"
white
"
)
else
:
if
survival
(
universe
,(
x
,
y
))
==
0
:
"
colorier la case zones[x][y] en rouge
"
canvas
.
itemconfig
(
zones
[
x
][
y
],
fill
=
"
red
"
)
else
:
"
colorier la case zones[x][y] en noir
"
canvas
.
itemconfig
(
zones
[
x
][
y
],
fill
=
"
black
"
)
universe
=
generation
(
universe
)
def
create_cell_on_click
(
event
):
"""
créer une cellule vivante la ou l
'
utilisateur clique
"""
global
universe
x
=
event
.
x
//
10
y
=
event
.
y
//
10
universe
[
x
][
y
]
=
1
def
add_seed_tk
():
"""
ajoute la graine donnée dans la fenetre principale
"""
global
universe
type_seed
=
ligne_texte
.
get
()
seed
=
create_seed
(
type_seed
)
try
:
x_start
=
rd
.
randint
(
0
,
100
-
len
(
seed
))
y_start
=
rd
.
randint
(
0
,
100
-
len
(
seed
[
0
]))
universe
=
add_seed_to_universe
(
seed
,
universe
,
x_start
,
y_start
)
except
:
print
(
"
la graine n
'
a pas etait ajouté
"
)
button_add_seed
=
Button
(
fenetre
,
text
=
"
ajoute la graine
"
,
command
=
add_seed_tk
)
button_add_seed
.
pack
()
button_next_step
=
Button
(
fenetre
,
text
=
"
go to next gen
"
,
command
=
update_grid
)
button_next_step
.
pack
()
create_a_grid
()
canvas
.
bind
(
"
<Button-1>
"
,
create_cell_on_click
)
fenetre
.
mainloop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment