Bonjour,

j'utilise Kivy et je pensais pouvoir utiliser une liste pour transmettre des paramètres lors de changement de fenêtre avec screenmanager. Or je m'aperçois que lorsque je modifie une liste et qu'ensuite je clique pour passer à l'écran suivant, ma liste est réinitialisée. Sauriez-vous comment remédier à ce problème svp?

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import kivy
kivy.require('1.9.0')
 
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.config import Config
 
 
#Config.set('graphics', 'width', '1366') 
#Config.set('graphics', 'height', '768') 
 
Config.set('graphics', 'fullscreen', 'auto') 
 
ecran4=["0"]
myBtn=[]
monText=["Ce bouton devrait afficher \"Thé\" ou \"Café\""]
 
 
class ScreenOne(Screen):
 
    def __init__(self, **kwargs):
 
        def do_action(self):
 
            if play.text=="Café" :
                play.text="Thé"
                monText[:]=[]
                monText.append("Thé")
                print("Thea : "+str(monText[0]))
            else :
                play.text="Café"
                monText[:]=[]
                monText.append("Café")
                print("Coffee : "+str(monText[0]))
        pass
 
        def do_action2(self):
           screen_manager.transition.direction = 'left'
           screen_manager.transition.duration = 0
           screen_manager.current = 'screen_two'
        pass
 
        super(ScreenOne, self).__init__(**kwargs)
        Layout1 = GridLayout(cols=1, row_force_default=True, row_default_height=40)
        self.add_widget(Layout1)
        play = Label(text = "Café")
        Layout1.add_widget(play)
        myBtn.append(play)
        changing = Layout1.add_widget(Button(text = "Changement", on_press=do_action))
        clickBtn = Button(text = "OK", on_press=do_action2)
        Layout1.add_widget(clickBtn)
 
class ScreenTwo(Screen):    
 
    def __init__(self, **kwargs):
 
        def do_action2(self):
            screen_manager.transition.direction = 'left'
            screen_manager.transition.duration = 0
            screen_manager.current = 'screen_one'
        pass
 
        super(ScreenTwo, self).__init__(**kwargs)
        ScreenTwo.clear_widgets(self)
        Layout2 = GridLayout(cols=1, row_force_default=True, row_default_height=40)
        self.add_widget(Layout2)
 
        print(monText[0])
 
        for nbBtn in range(10):
            monChoix = Button(text = monText[0], on_press=do_action2)
            Layout2.add_widget(monChoix)
            myBtn.append(monChoix)       
 
 
# The ScreenManager controls moving between screens
screen_manager = ScreenManager()
 
# Add the screens to the manager and then supply a name
# that is used to switch screens
screen_manager.add_widget(ScreenOne(name="screen_one"))
screen_manager.add_widget(ScreenTwo(name="screen_two"))
 
class KivyTut2App(App):
 
    def build(self):
        screen_manager.current = 'screen_one' 
        return screen_manager
 
sample_app = KivyTut2App()
sample_app.run()