Bonjour,

Je suis une nouvelle fois bloqué.

Le bouton Stop/Start est sensé changer la variable self.game_status mais ensuite je n'arrive pas à transférer le nouvelle état de self.game_status à la class update_tableau.

Dans un premier temps, j'appelle update_tableau dans le init de Application pour lui transmettre la variable can du canvas et self.game_status . Ca me parait maintenant logique que modifier par la suite self.game_status dans la classe application n'impacte pas la valeur de la variable que j'ai envoyé en instanciant la classe update_tableau mais je n'ai pas de solution.

Comment faire ? je pense pas régler le problème par l'héritage ou un agrégat.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from tkinter import * 
 
CASE_SIZE = 20
CASE_NUMBER = 20
 
class Application(Frame):   
 
    def __init__(self, boss =None):
        super().__init__() 
        self.pack()  
        self.game_status = 0 
 
        size = CASE_NUMBER*CASE_SIZE
        size = CASE_NUMBER*CASE_SIZE 
        self.can = Canvas(self, width=size, height=size, bg ="black")
 
        button_start = Button(self, text ='Stop/Start',command =self.launch_game)
        button_start.pack(side = RIGHT)
        self.pack()
        update_tableau(self.game_status, self.can)
 
    def launch_game(self):
        self.game_status = not(self.game_status) 
        print(1,':', self.game_status)
 
 
class update_tableau(Application):
    def __init__(self, game_status,can):
        self.game_status = game_status
        self.can = can
        self.parcourt_tableau()
 
    def parcourt_tableau(self):
            print(2,':', self.game_status)            
            self.can.after(200,self.parcourt_tableau)          
 
launch = Application()
launch.mainloop()
Merci