質問編集履歴

2

コードを編集しました

2021/03/09 09:32

投稿

geekmama
geekmama

スコア1

test CHANGED
File without changes
test CHANGED
@@ -30,37 +30,7 @@
30
30
 
31
31
  ```Python
32
32
 
33
- import tkinter as tk
33
+
34
-
35
- import time
36
-
37
-
38
-
39
- class Application(tk.Frame):
40
-
41
- def __init__(self, master=None):
42
-
43
- super().__init__(master)
44
-
45
- self.master.title('カウントダウンタイマー')
46
-
47
- self.master.geometry('520x250')
48
-
49
- self.target_time = None
50
-
51
- self.create_widgets()
52
-
53
-
54
-
55
- def create_widgets(self):
56
-
57
-
58
-
59
- f_input = tk.Frame(self)
60
-
61
- f_input.pack()
62
-
63
-
64
34
 
65
35
  f_entry = tk.Frame(f_input, pady=20)
66
36
 
@@ -76,283 +46,13 @@
76
46
 
77
47
 
78
48
 
79
- f_btn1 = tk.Frame(f_input, pady=20)
80
49
 
81
- f_btn1.pack(side=tk.LEFT)
82
50
 
83
- self.b_30s = tk.Button(f_btn1, text="30秒", command=lambda:[self.set_30s(), self.start()])
84
-
85
- self.b_1m = tk.Button(f_btn1, text="1分", command=lambda:[self.set_1m(), self.start()])
86
-
87
- self.b_90s = tk.Button(f_btn1, text="90秒", command=lambda:[self.set_90s(), self.start()])
88
-
89
- self.b_2m = tk.Button(f_btn1, text="2分", command=lambda:[self.set_2m(), self.start()])
90
-
91
- self.b_3m = tk.Button(f_btn1, text="3分", command=lambda:[self.set_3m(), self.start()])
92
-
93
- self.b_4m = tk.Button(f_btn1, text="4分", command=lambda:[self.set_4m(), self.start()])
94
-
95
- self.b_5m = tk.Button(f_btn1, text="5分", command=lambda:[self.set_5m(), self.start()])
96
-
97
- self.b_6m = tk.Button(f_btn1, text="6分", command=lambda:[self.set_6m(), self.start()])
98
-
99
- self.b_10m = tk.Button(f_btn1, text="10分", command=lambda:[self.set_10m(), self.start()])
100
-
101
- self.b_20m = tk.Button(f_btn1, text="20分", command=lambda:[self.set_20m(), self.start()])
102
-
103
- self.b_30m = tk.Button(f_btn1, text="30分", command=lambda:[self.set_30m(), self.start()])
104
-
105
- self.b_1h = tk.Button(f_btn1, text="1時間", command=lambda:[self.set_1h(), self.start()])
106
-
107
- self.b_30s.pack(side=tk.LEFT,padx=5)
108
-
109
- self.b_1m.pack(side=tk.LEFT,padx=5)
51
+ ====== 中略 ======
110
-
111
- self.b_90s.pack(side=tk.LEFT,padx=5)
112
-
113
- self.b_2m.pack(side=tk.LEFT,padx=5)
114
-
115
- self.b_3m.pack(side=tk.LEFT,padx=5)
116
-
117
- self.b_4m.pack(side=tk.LEFT,padx=5)
118
-
119
- self.b_5m.pack(side=tk.LEFT,padx=5)
120
-
121
- self.b_6m.pack(side=tk.LEFT,padx=5)
122
-
123
- self.b_10m.pack(side=tk.LEFT,padx=5)
124
-
125
- self.b_20m.pack(side=tk.LEFT,padx=5)
126
-
127
- self.b_30m.pack(side=tk.LEFT,padx=5)
128
-
129
- self.b_1h.pack(side=tk.LEFT,padx=5)
130
52
 
131
53
 
132
54
 
133
- self.svar = tk.StringVar()
55
+
134
-
135
- self.time_init()
136
-
137
- self.display = tk.Label(self, textvariable=self.svar, relief=tk.SUNKEN, font=("Meiryo",20),bg="white")
138
-
139
- self.display.pack(fill=tk.X, expand=1)
140
-
141
-
142
-
143
- f_btn2 = tk.Frame(self, pady=20)
144
-
145
- f_btn2.pack()
146
-
147
- self.b_start = tk.Button(f_btn2, text="スタート", command=self.start)
148
-
149
- self.b_stop = tk.Button(f_btn2, text="一時停止", command=self.stop, state=tk.DISABLED)
150
-
151
- self.b_reset = tk.Button(f_btn2, text="リセット", command=self.reset, state=tk.DISABLED)
152
-
153
- self.b_start.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
154
-
155
- self.b_stop.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
156
-
157
- self.b_reset.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
158
-
159
-
160
-
161
-
162
-
163
- def time_init(self):
164
-
165
- self.svar.set("時間ボタンをクリックしてください")
166
-
167
-
168
-
169
- def time_err(self,s):
170
-
171
- self.svar.set(f"{s}は不正な数値です。")
172
-
173
-
174
-
175
- def time_set(self):
176
-
177
- self.h = self.target_time // 3600
178
-
179
- self.m = (self.target_time % 3600) // 60
180
-
181
- self.s = (self.target_time % 3600) % 60
182
-
183
- self.svar.set("残 %02d時間 %02d分 %02d秒" % (self.h,self.m,self.s))
184
-
185
-
186
-
187
- def deltatime(self):
188
-
189
- return (time.time() - self.pretime)
190
-
191
-
192
-
193
- def set_30s(self):
194
-
195
- self.entry.delete(0,tk.END)
196
-
197
- self.entry.insert(tk.END,"30")
198
-
199
-
200
-
201
- def set_1m(self):
202
-
203
- self.entry.delete(0,tk.END)
204
-
205
- self.entry.insert(tk.END,"60")
206
-
207
-
208
-
209
- def set_90s(self):
210
-
211
- self.entry.delete(0,tk.END)
212
-
213
- self.entry.insert(tk.END,"90")
214
-
215
-
216
-
217
- def set_2m(self):
218
-
219
- self.entry.delete(0,tk.END)
220
-
221
- self.entry.insert(tk.END,"120")
222
-
223
-
224
-
225
- def set_3m(self):
226
-
227
- self.entry.delete(0,tk.END)
228
-
229
- self.entry.insert(tk.END,"180")
230
-
231
-
232
-
233
- def set_4m(self):
234
-
235
- self.entry.delete(0,tk.END)
236
-
237
- self.entry.insert(tk.END,"240")
238
-
239
-
240
-
241
- def set_5m(self):
242
-
243
- self.entry.delete(0,tk.END)
244
-
245
- self.entry.insert(tk.END,"300")
246
-
247
-
248
-
249
- def set_6m(self):
250
-
251
- self.entry.delete(0,tk.END)
252
-
253
- self.entry.insert(tk.END,"360")
254
-
255
-
256
-
257
- def set_10m(self):
258
-
259
- self.entry.delete(0,tk.END)
260
-
261
- self.entry.insert(tk.END,"600")
262
-
263
-
264
-
265
- def set_20m(self):
266
-
267
- self.entry.delete(0,tk.END)
268
-
269
- self.entry.insert(tk.END,"1200")
270
-
271
-
272
-
273
- def set_30m(self):
274
-
275
- self.entry.delete(0,tk.END)
276
-
277
- self.entry.insert(tk.END,"1800")
278
-
279
-
280
-
281
- def set_1h(self):
282
-
283
- self.entry.delete(0,tk.END)
284
-
285
- self.entry.insert(tk.END,"3600")
286
-
287
-
288
-
289
- def start(self):
290
-
291
- try:
292
-
293
- if not self.target_time:
294
-
295
- self.target_time = int(self.entry.get())
296
-
297
- except:
298
-
299
- self.time_err(self.entry.get())
300
-
301
- return
302
-
303
- self.started = True
304
-
305
- self.pretime = time.time()
306
-
307
- self.time_set()
308
-
309
- self.entry.config(state=tk.DISABLED)
310
-
311
- self.b_start.config(state=tk.DISABLED)
312
-
313
- self.b_stop.config(state=tk.NORMAL)
314
-
315
- self.b_reset.config(state=tk.NORMAL)
316
-
317
- self.b_30s.config(state=tk.DISABLED)
318
-
319
- self.b_1m.config(state=tk.DISABLED)
320
-
321
- self.b_90s.config(state=tk.DISABLED)
322
-
323
- self.b_2m.config(state=tk.DISABLED)
324
-
325
- self.b_3m.config(state=tk.DISABLED)
326
-
327
- self.b_4m.config(state=tk.DISABLED)
328
-
329
- self.b_5m.config(state=tk.DISABLED)
330
-
331
- self.b_6m.config(state=tk.DISABLED)
332
-
333
- self.b_10m.config(state=tk.DISABLED)
334
-
335
- self.b_20m.config(state=tk.DISABLED)
336
-
337
- self.b_30m.config(state=tk.DISABLED)
338
-
339
- self.b_1h.config(state=tk.DISABLED)
340
-
341
- self.exec_timer()
342
-
343
-
344
-
345
- def stop(self):
346
-
347
- self.started = False
348
-
349
- self.b_start.config(state=tk.NORMAL)
350
-
351
- self.b_stop.config(state=tk.DISABLED)
352
-
353
- self.b_reset.config(state=tk.NORMAL)
354
-
355
-
356
56
 
357
57
  def reset(self):
358
58
 
@@ -400,38 +100,6 @@
400
100
 
401
101
 
402
102
 
403
-
404
-
405
- def exec_timer(self):
406
-
407
- if self.started:
408
-
409
- self.target_time = self.target_time - self.deltatime()
410
-
411
- self.time_set()
412
-
413
-
414
-
415
- if self.target_time <= 11:
416
-
417
- self.display.config(bg="plum")
418
-
419
-
420
-
421
- self.pretime = time.time()
422
-
423
- self.after(50, self.exec_timer)
424
-
425
-
426
-
427
- if __name__ == '__main__':
428
-
429
- app = Application()
430
-
431
- app.pack()
432
-
433
- app.mainloop()
434
-
435
103
  ```
436
104
 
437
105
 

1

2021/03/09 09:32

投稿

geekmama
geekmama

スコア1

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- エラーメッセージ:なし
19
+ エラーメッセージ:TypeError
20
20
 
21
21
  前回のセット時間が残ってしまう
22
22
 
@@ -360,7 +360,7 @@
360
360
 
361
361
  self.target_time = None
362
362
 
363
- #self.entry.delete() #空欄にしたい
363
+ self.entry.delete()
364
364
 
365
365
  self.time_init()
366
366
 
@@ -444,7 +444,7 @@
444
444
 
445
445
  self.entry.delete()
446
446
 
447
- 追加してみるも、TypeErrorとなり機能ません
447
+ 追加し
448
448
 
449
449
 
450
450