質問編集履歴
1
コード部分にはりつけした
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,211 +18,213 @@
|
|
18
18
|
|
19
19
|
### 該当のソースコード
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
```python
|
24
|
-
|
25
21
|
ソースコード
|
26
22
|
|
23
|
+
``````
|
24
|
+
|
25
|
+
from kivy.config import Config
|
26
|
+
|
27
|
+
Config.set('graphics', 'width', '300')
|
28
|
+
|
29
|
+
Config.set('graphics', 'height', '150')
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
from kivy.lang import Builder
|
34
|
+
|
35
|
+
from kivy.uix.widget import Widget
|
36
|
+
|
37
|
+
from kivy.uix.boxlayout import BoxLayout
|
38
|
+
|
39
|
+
from kivy.uix.label import Label
|
40
|
+
|
41
|
+
from kivy.uix.button import Button
|
42
|
+
|
43
|
+
from kivy.properties import BooleanProperty
|
44
|
+
|
45
|
+
from kivy.properties import NumericProperty
|
46
|
+
|
47
|
+
from kivy.clock import Clock
|
48
|
+
|
49
|
+
from kivy.app import App
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
import pygame.mixer
|
54
|
+
|
55
|
+
import time
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
**def sound():
|
60
|
+
|
61
|
+
pygame.mixer.init()
|
62
|
+
|
63
|
+
pygame.mixer.music.load("/Users/.mp3")
|
64
|
+
|
65
|
+
pygame.mixer.music.play(1)
|
66
|
+
|
67
|
+
time.sleep(1)
|
68
|
+
|
69
|
+
pygame.mixer.music.stop()**
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Builder.load_string('''
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<KivyTimer>:
|
78
|
+
|
79
|
+
BoxLayout:
|
80
|
+
|
81
|
+
orientation: 'vertical'
|
82
|
+
|
83
|
+
pos: root.pos
|
84
|
+
|
85
|
+
size: root.size
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
Label:
|
90
|
+
|
91
|
+
text: str(root.left_time)
|
92
|
+
|
93
|
+
font_size: 200
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
BoxLayout:
|
98
|
+
|
99
|
+
orientation: 'horizontal'
|
100
|
+
|
101
|
+
size_hint: 1.0, 0.3
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
Button:
|
106
|
+
|
107
|
+
text: '+10 seconds'
|
108
|
+
|
109
|
+
font_size:
|
110
|
+
|
111
|
+
on_press: root.on_command('+10 seconds')
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
Button:
|
116
|
+
|
117
|
+
text: 'Stop' if root.is_countdown else 'Start'
|
118
|
+
|
119
|
+
font_size: 16
|
120
|
+
|
121
|
+
on_press: root.on_command('start/stop')
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
Button:
|
126
|
+
|
127
|
+
text: 'Reset'
|
128
|
+
|
129
|
+
font_size: 16
|
130
|
+
|
131
|
+
on_press: root.on_command('reset')
|
132
|
+
|
133
|
+
''')
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
class KivyTimer(Widget):
|
140
|
+
|
141
|
+
is_countdown = BooleanProperty(False)
|
142
|
+
|
143
|
+
left_time = NumericProperty(0)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
def on_command(self, command):
|
148
|
+
|
149
|
+
if command == '+10 seconds':
|
150
|
+
|
151
|
+
self.left_time += 10
|
152
|
+
|
153
|
+
elif command == 'start/stop':
|
154
|
+
|
155
|
+
if self.is_countdown:
|
156
|
+
|
157
|
+
self.stop_timer()
|
158
|
+
|
159
|
+
elif self.left_time > 0:
|
160
|
+
|
161
|
+
self.start_timer()
|
162
|
+
|
163
|
+
elif command == 'reset':
|
164
|
+
|
165
|
+
self.stop_timer()
|
166
|
+
|
167
|
+
self.left_time = 0
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
def on_countdown(self, dt):
|
172
|
+
|
173
|
+
self.left_time -= 1
|
174
|
+
|
175
|
+
if self.left_time == 0:
|
176
|
+
|
177
|
+
self.is_countdown = False
|
178
|
+
|
179
|
+
return False
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def start_timer(self):
|
188
|
+
|
189
|
+
self.is_countdown = True
|
190
|
+
|
191
|
+
Clock.schedule_interval(self.on_countdown, 1.0)
|
192
|
+
|
193
|
+
pass
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
def stop_timer(self):
|
198
|
+
|
199
|
+
self.is_countdown = False
|
200
|
+
|
201
|
+
Clock.unschedule(self.on_countdown)
|
202
|
+
|
203
|
+
pass
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
class KivyTimerApp(App):
|
210
|
+
|
211
|
+
def build(self):
|
212
|
+
|
213
|
+
return KivyTimer()
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if __name__ == '__main__':
|
220
|
+
|
221
|
+
KivyTimerApp().run()
|
222
|
+
|
223
|
+
コード
|
224
|
+
|
27
225
|
```
|
28
226
|
|
29
|
-
|
227
|
+
|
30
|
-
|
31
|
-
Config.set('graphics', 'width', '300')
|
32
|
-
|
33
|
-
Config.set('graphics', 'height', '150')
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
from kivy.lang import Builder
|
38
|
-
|
39
|
-
from kivy.uix.widget import Widget
|
40
|
-
|
41
|
-
from kivy.uix.boxlayout import BoxLayout
|
42
|
-
|
43
|
-
from kivy.uix.label import Label
|
44
|
-
|
45
|
-
from kivy.uix.button import Button
|
46
|
-
|
47
|
-
from kivy.properties import BooleanProperty
|
48
|
-
|
49
|
-
from kivy.properties import NumericProperty
|
50
|
-
|
51
|
-
from kivy.clock import Clock
|
52
|
-
|
53
|
-
from kivy.app import App
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
import pygame.mixer
|
58
|
-
|
59
|
-
import time
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
**def sound():
|
64
|
-
|
65
|
-
pygame.mixer.init()
|
66
|
-
|
67
|
-
pygame.mixer.music.load("/Users/.mp3")
|
68
|
-
|
69
|
-
pygame.mixer.music.play(1)
|
70
|
-
|
71
|
-
time.sleep(1)
|
72
|
-
|
73
|
-
pygame.mixer.music.stop()**
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
Builder.load_string('''
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
<KivyTimer>:
|
82
|
-
|
83
|
-
BoxLayout:
|
84
|
-
|
85
|
-
orientation: 'vertical'
|
86
|
-
|
87
|
-
pos: root.pos
|
88
|
-
|
89
|
-
size: root.size
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
Label:
|
94
|
-
|
95
|
-
text: str(root.left_time)
|
96
|
-
|
97
|
-
font_size: 200
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
BoxLayout:
|
102
|
-
|
103
|
-
orientation: 'horizontal'
|
104
|
-
|
105
|
-
size_hint: 1.0, 0.3
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
Button:
|
110
|
-
|
111
|
-
text: '+10 seconds'
|
112
|
-
|
113
|
-
font_size:
|
114
|
-
|
115
|
-
on_press: root.on_command('+10 seconds')
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Button:
|
120
|
-
|
121
|
-
text: 'Stop' if root.is_countdown else 'Start'
|
122
|
-
|
123
|
-
font_size: 16
|
124
|
-
|
125
|
-
on_press: root.on_command('start/stop')
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
Button:
|
130
|
-
|
131
|
-
text: 'Reset'
|
132
|
-
|
133
|
-
font_size: 16
|
134
|
-
|
135
|
-
on_press: root.on_command('reset')
|
136
|
-
|
137
|
-
''')
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
class KivyTimer(Widget):
|
144
|
-
|
145
|
-
is_countdown = BooleanProperty(False)
|
146
|
-
|
147
|
-
left_time = NumericProperty(0)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
def on_command(self, command):
|
152
|
-
|
153
|
-
if command == '+10 seconds':
|
154
|
-
|
155
|
-
self.left_time += 10
|
156
|
-
|
157
|
-
elif command == 'start/stop':
|
158
|
-
|
159
|
-
if self.is_countdown:
|
160
|
-
|
161
|
-
self.stop_timer()
|
162
|
-
|
163
|
-
elif self.left_time > 0:
|
164
|
-
|
165
|
-
self.start_timer()
|
166
|
-
|
167
|
-
elif command == 'reset':
|
168
|
-
|
169
|
-
self.stop_timer()
|
170
|
-
|
171
|
-
self.left_time = 0
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
def on_countdown(self, dt):
|
176
|
-
|
177
|
-
self.left_time -= 1
|
178
|
-
|
179
|
-
if self.left_time == 0:
|
180
|
-
|
181
|
-
self.is_countdown = False
|
182
|
-
|
183
|
-
return False
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
def start_timer(self):
|
192
|
-
|
193
|
-
self.is_countdown = True
|
194
|
-
|
195
|
-
Clock.schedule_interval(self.on_countdown, 1.0)
|
196
|
-
|
197
|
-
pass
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
def stop_timer(self):
|
202
|
-
|
203
|
-
self.is_countdown = False
|
204
|
-
|
205
|
-
Clock.unschedule(self.on_countdown)
|
206
|
-
|
207
|
-
pass
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
class KivyTimerApp(App):
|
214
|
-
|
215
|
-
def build(self):
|
216
|
-
|
217
|
-
return KivyTimer()
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
if __name__ == '__main__':
|
224
|
-
|
225
|
-
KivyTimerApp().run()
|
226
228
|
|
227
229
|
### 試したこと
|
228
230
|
|