質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -47,4 +47,80 @@
|
|
47
47
|
Button:
|
48
48
|
text: "Start delay"
|
49
49
|
on_press: root.start_delay()
|
50
|
+
```
|
51
|
+
追記 2018/2/1
|
52
|
+
期待した結果が得られたコード
|
53
|
+
```Python
|
54
|
+
# -*- coding: utf-8 -*
|
55
|
+
from kivy.app import App
|
56
|
+
from kivy.lang import Builder
|
57
|
+
from kivy.uix.boxlayout import BoxLayout
|
58
|
+
from kivy.clock import Clock
|
59
|
+
Builder.load_string("""
|
60
|
+
<MainFrame>:
|
61
|
+
orientation: "vertical"
|
62
|
+
Label:
|
63
|
+
id: info
|
64
|
+
text: "not yet"
|
65
|
+
Button:
|
66
|
+
text: "Start delay"
|
67
|
+
on_press: root.start_delay()
|
68
|
+
""")
|
69
|
+
|
70
|
+
class MainFrame(BoxLayout):
|
71
|
+
|
72
|
+
def __init__(self, **kwargs):
|
73
|
+
super(MainFrame, self).__init__(**kwargs)
|
74
|
+
|
75
|
+
def start_delay(self):
|
76
|
+
def callback(dt):
|
77
|
+
self.ids["info"].text = "Done"
|
78
|
+
Clock.schedule_once(callback, 3)
|
79
|
+
|
80
|
+
|
81
|
+
class delay_test(App):
|
82
|
+
def build(self):
|
83
|
+
return MainFrame()
|
84
|
+
|
85
|
+
|
86
|
+
if __name__ == "__main__":
|
87
|
+
delay_test().run()
|
88
|
+
```
|
89
|
+
上のコードを別のやり方でやろうとしたコード
|
90
|
+
結果、エラーで強制終了。
|
91
|
+
```Python
|
92
|
+
# -*- coding: utf-8 -*
|
93
|
+
from kivy.app import App
|
94
|
+
from kivy.lang import Builder
|
95
|
+
from kivy.uix.boxlayout import BoxLayout
|
96
|
+
from kivy.clock import Clock
|
97
|
+
Builder.load_string("""
|
98
|
+
<MainFrame>:
|
99
|
+
orientation: "vertical"
|
100
|
+
Label:
|
101
|
+
id: info
|
102
|
+
text: "not yet"
|
103
|
+
Button:
|
104
|
+
text: "Start delay"
|
105
|
+
on_press: root.start_delay()
|
106
|
+
""")
|
107
|
+
|
108
|
+
class MainFrame(BoxLayout):
|
109
|
+
|
110
|
+
def __init__(self, **kwargs):
|
111
|
+
super(MainFrame, self).__init__(**kwargs)
|
112
|
+
|
113
|
+
def start_delay(self):
|
114
|
+
Clock.schedule_once(self.change_text, 3)
|
115
|
+
|
116
|
+
def change_text(self):
|
117
|
+
self.ids["info"].text = "Done"
|
118
|
+
|
119
|
+
class delay_test(App):
|
120
|
+
def build(self):
|
121
|
+
return MainFrame()
|
122
|
+
|
123
|
+
|
124
|
+
if __name__ == "__main__":
|
125
|
+
delay_test().run()
|
50
126
|
```
|