質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -97,3 +97,155 @@
|
|
97
97
|
on_press: root.start_delay()
|
98
98
|
|
99
99
|
```
|
100
|
+
|
101
|
+
追記 2018/2/1
|
102
|
+
|
103
|
+
期待した結果が得られたコード
|
104
|
+
|
105
|
+
```Python
|
106
|
+
|
107
|
+
# -*- coding: utf-8 -*
|
108
|
+
|
109
|
+
from kivy.app import App
|
110
|
+
|
111
|
+
from kivy.lang import Builder
|
112
|
+
|
113
|
+
from kivy.uix.boxlayout import BoxLayout
|
114
|
+
|
115
|
+
from kivy.clock import Clock
|
116
|
+
|
117
|
+
Builder.load_string("""
|
118
|
+
|
119
|
+
<MainFrame>:
|
120
|
+
|
121
|
+
orientation: "vertical"
|
122
|
+
|
123
|
+
Label:
|
124
|
+
|
125
|
+
id: info
|
126
|
+
|
127
|
+
text: "not yet"
|
128
|
+
|
129
|
+
Button:
|
130
|
+
|
131
|
+
text: "Start delay"
|
132
|
+
|
133
|
+
on_press: root.start_delay()
|
134
|
+
|
135
|
+
""")
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
class MainFrame(BoxLayout):
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
def __init__(self, **kwargs):
|
144
|
+
|
145
|
+
super(MainFrame, self).__init__(**kwargs)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def start_delay(self):
|
150
|
+
|
151
|
+
def callback(dt):
|
152
|
+
|
153
|
+
self.ids["info"].text = "Done"
|
154
|
+
|
155
|
+
Clock.schedule_once(callback, 3)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
class delay_test(App):
|
162
|
+
|
163
|
+
def build(self):
|
164
|
+
|
165
|
+
return MainFrame()
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
if __name__ == "__main__":
|
172
|
+
|
173
|
+
delay_test().run()
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
上のコードを別のやり方でやろうとしたコード
|
178
|
+
|
179
|
+
結果、エラーで強制終了。
|
180
|
+
|
181
|
+
```Python
|
182
|
+
|
183
|
+
# -*- coding: utf-8 -*
|
184
|
+
|
185
|
+
from kivy.app import App
|
186
|
+
|
187
|
+
from kivy.lang import Builder
|
188
|
+
|
189
|
+
from kivy.uix.boxlayout import BoxLayout
|
190
|
+
|
191
|
+
from kivy.clock import Clock
|
192
|
+
|
193
|
+
Builder.load_string("""
|
194
|
+
|
195
|
+
<MainFrame>:
|
196
|
+
|
197
|
+
orientation: "vertical"
|
198
|
+
|
199
|
+
Label:
|
200
|
+
|
201
|
+
id: info
|
202
|
+
|
203
|
+
text: "not yet"
|
204
|
+
|
205
|
+
Button:
|
206
|
+
|
207
|
+
text: "Start delay"
|
208
|
+
|
209
|
+
on_press: root.start_delay()
|
210
|
+
|
211
|
+
""")
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
class MainFrame(BoxLayout):
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
def __init__(self, **kwargs):
|
220
|
+
|
221
|
+
super(MainFrame, self).__init__(**kwargs)
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
def start_delay(self):
|
226
|
+
|
227
|
+
Clock.schedule_once(self.change_text, 3)
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
def change_text(self):
|
232
|
+
|
233
|
+
self.ids["info"].text = "Done"
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
class delay_test(App):
|
238
|
+
|
239
|
+
def build(self):
|
240
|
+
|
241
|
+
return MainFrame()
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
if __name__ == "__main__":
|
248
|
+
|
249
|
+
delay_test().run()
|
250
|
+
|
251
|
+
```
|