質問編集履歴

3

タイトルを変更

2021/03/09 09:29

投稿

geekmama
geekmama

スコア1

test CHANGED
@@ -1 +1 @@
1
- タイマーの残時間をマイナス表示にする方法を教えてください
1
+ タイマーの残時間をマイナス表示にする方法を教えてください
test CHANGED
File without changes

2

不要なコードを削除

2021/03/09 09:29

投稿

geekmama
geekmama

スコア1

test CHANGED
File without changes
test CHANGED
@@ -24,134 +24,6 @@
24
24
 
25
25
  ```Python
26
26
 
27
- import tkinter as tk
28
-
29
- import time
30
-
31
-
32
-
33
- class Application(tk.Frame):
34
-
35
- def __init__(self, master=None):
36
-
37
- super().__init__(master)
38
-
39
- self.master.title('カウントダウンタイマー')
40
-
41
- self.master.geometry('520x250')
42
-
43
- self.target_time = None
44
-
45
- self.create_widgets()
46
-
47
-
48
-
49
- def create_widgets(self):
50
-
51
-
52
-
53
- f_input = tk.Frame(self)
54
-
55
- f_input.pack()
56
-
57
-
58
-
59
- f_entry = tk.Frame(f_input, pady=20)
60
-
61
- f_entry.pack(side=tk.TOP)
62
-
63
- self.entry = tk.Entry(f_entry, width=5)
64
-
65
- self.entry.insert(tk.END,"")
66
-
67
- self.entry.pack(fill='x', padx=5, side='left')
68
-
69
- tk.Label(f_entry,text="秒 (手入力も可能です)").pack(fill='x', padx=5, side='left')
70
-
71
-
72
-
73
- f_btn1 = tk.Frame(f_input, pady=20)
74
-
75
- f_btn1.pack(side=tk.LEFT)
76
-
77
- self.b_30s = tk.Button(f_btn1, text="30秒", command=lambda:[self.set_30s(), self.start()])
78
-
79
- self.b_1m = tk.Button(f_btn1, text="1分", command=lambda:[self.set_1m(), self.start()])
80
-
81
- self.b_90s = tk.Button(f_btn1, text="90秒", command=lambda:[self.set_90s(), self.start()])
82
-
83
- self.b_2m = tk.Button(f_btn1, text="2分", command=lambda:[self.set_2m(), self.start()])
84
-
85
- self.b_3m = tk.Button(f_btn1, text="3分", command=lambda:[self.set_3m(), self.start()])
86
-
87
- self.b_4m = tk.Button(f_btn1, text="4分", command=lambda:[self.set_4m(), self.start()])
88
-
89
- self.b_5m = tk.Button(f_btn1, text="5分", command=lambda:[self.set_5m(), self.start()])
90
-
91
- self.b_6m = tk.Button(f_btn1, text="6分", command=lambda:[self.set_6m(), self.start()])
92
-
93
- self.b_10m = tk.Button(f_btn1, text="10分", command=lambda:[self.set_10m(), self.start()])
94
-
95
- self.b_20m = tk.Button(f_btn1, text="20分", command=lambda:[self.set_20m(), self.start()])
96
-
97
- self.b_30m = tk.Button(f_btn1, text="30分", command=lambda:[self.set_30m(), self.start()])
98
-
99
- self.b_1h = tk.Button(f_btn1, text="1時間", command=lambda:[self.set_1h(), self.start()])
100
-
101
- self.b_30s.pack(side=tk.LEFT,padx=5)
102
-
103
- self.b_1m.pack(side=tk.LEFT,padx=5)
104
-
105
- self.b_90s.pack(side=tk.LEFT,padx=5)
106
-
107
- self.b_2m.pack(side=tk.LEFT,padx=5)
108
-
109
- self.b_3m.pack(side=tk.LEFT,padx=5)
110
-
111
- self.b_4m.pack(side=tk.LEFT,padx=5)
112
-
113
- self.b_5m.pack(side=tk.LEFT,padx=5)
114
-
115
- self.b_6m.pack(side=tk.LEFT,padx=5)
116
-
117
- self.b_10m.pack(side=tk.LEFT,padx=5)
118
-
119
- self.b_20m.pack(side=tk.LEFT,padx=5)
120
-
121
- self.b_30m.pack(side=tk.LEFT,padx=5)
122
-
123
- self.b_1h.pack(side=tk.LEFT,padx=5)
124
-
125
-
126
-
127
- self.svar = tk.StringVar()
128
-
129
- self.time_init()
130
-
131
- self.display = tk.Label(self, textvariable=self.svar, relief=tk.SUNKEN, font=("Meiryo",20),bg="white")
132
-
133
- self.display.pack(fill=tk.X, expand=1)
134
-
135
-
136
-
137
- f_btn2 = tk.Frame(self, pady=20)
138
-
139
- f_btn2.pack()
140
-
141
- self.b_start = tk.Button(f_btn2, text="スタート", command=self.start)
142
-
143
- self.b_stop = tk.Button(f_btn2, text="一時停止", command=self.stop, state=tk.DISABLED)
144
-
145
- self.b_reset = tk.Button(f_btn2, text="リセット", command=self.reset, state=tk.DISABLED)
146
-
147
- self.b_start.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
148
-
149
- self.b_stop.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
150
-
151
- self.b_reset.pack(side=tk.LEFT, padx=10, ipadx=20, ipady=10)
152
-
153
-
154
-
155
27
 
156
28
 
157
29
  def time_init(self):
@@ -162,7 +34,7 @@
162
34
 
163
35
  def time_err(self,s):
164
36
 
165
- self.svar.set(f'{s}は不正な数値です。')
37
+ self.svar.set(f"{s}は不正な数値です")
166
38
 
167
39
 
168
40
 
@@ -184,254 +56,6 @@
184
56
 
185
57
 
186
58
 
187
- def set_30s(self):
188
-
189
- self.entry.delete(0,tk.END)
190
-
191
- self.entry.insert(tk.END,"30")
192
-
193
-
194
-
195
- def set_1m(self):
196
-
197
- self.entry.delete(0,tk.END)
198
-
199
- self.entry.insert(tk.END,"60")
200
-
201
-
202
-
203
- def set_90s(self):
204
-
205
- self.entry.delete(0,tk.END)
206
-
207
- self.entry.insert(tk.END,"90")
208
-
209
-
210
-
211
- def set_2m(self):
212
-
213
- self.entry.delete(0,tk.END)
214
-
215
- self.entry.insert(tk.END,"120")
216
-
217
-
218
-
219
- def set_3m(self):
220
-
221
- self.entry.delete(0,tk.END)
222
-
223
- self.entry.insert(tk.END,"180")
224
-
225
-
226
-
227
- def set_4m(self):
228
-
229
- self.entry.delete(0,tk.END)
230
-
231
- self.entry.insert(tk.END,"240")
232
-
233
-
234
-
235
- def set_5m(self):
236
-
237
- self.entry.delete(0,tk.END)
238
-
239
- self.entry.insert(tk.END,"300")
240
-
241
-
242
-
243
- def set_6m(self):
244
-
245
- self.entry.delete(0,tk.END)
246
-
247
- self.entry.insert(tk.END,"360")
248
-
249
-
250
-
251
- def set_10m(self):
252
-
253
- self.entry.delete(0,tk.END)
254
-
255
- self.entry.insert(tk.END,"600")
256
-
257
-
258
-
259
- def set_20m(self):
260
-
261
- self.entry.delete(0,tk.END)
262
-
263
- self.entry.insert(tk.END,"1200")
264
-
265
-
266
-
267
- def set_30m(self):
268
-
269
- self.entry.delete(0,tk.END)
270
-
271
- self.entry.insert(tk.END,"1800")
272
-
273
-
274
-
275
- def set_1h(self):
276
-
277
- self.entry.delete(0,tk.END)
278
-
279
- self.entry.insert(tk.END,"3600")
280
-
281
-
282
-
283
- def start(self):
284
-
285
- try:
286
-
287
- if not self.target_time:
288
-
289
- self.target_time = int(self.entry.get())
290
-
291
- except:
292
-
293
- self.time_err(self.entry.get())
294
-
295
- return
296
-
297
- self.started = True
298
-
299
- self.pretime = time.time()
300
-
301
- self.time_set()
302
-
303
- self.entry.config(state=tk.DISABLED)
304
-
305
- self.b_start.config(state=tk.DISABLED)
306
-
307
- self.b_stop.config(state=tk.NORMAL)
308
-
309
- self.b_reset.config(state=tk.NORMAL)
310
-
311
- self.b_30s.config(state=tk.DISABLED)
312
-
313
- self.b_1m.config(state=tk.DISABLED)
314
-
315
- self.b_90s.config(state=tk.DISABLED)
316
-
317
- self.b_2m.config(state=tk.DISABLED)
318
-
319
- self.b_3m.config(state=tk.DISABLED)
320
-
321
- self.b_4m.config(state=tk.DISABLED)
322
-
323
- self.b_5m.config(state=tk.DISABLED)
324
-
325
- self.b_6m.config(state=tk.DISABLED)
326
-
327
- self.b_10m.config(state=tk.DISABLED)
328
-
329
- self.b_20m.config(state=tk.DISABLED)
330
-
331
- self.b_30m.config(state=tk.DISABLED)
332
-
333
- self.b_1h.config(state=tk.DISABLED)
334
-
335
- self.exec_timer()
336
-
337
-
338
-
339
- def stop(self):
340
-
341
- self.started = False
342
-
343
- self.b_start.config(state=tk.NORMAL)
344
-
345
- self.b_stop.config(state=tk.DISABLED)
346
-
347
- self.b_reset.config(state=tk.NORMAL)
348
-
349
-
350
-
351
- def reset(self):
352
-
353
- self.started = False
354
-
355
- self.target_time = None
356
-
357
- self.time_init()
358
-
359
- self.display.config(bg="white")
360
-
361
- self.b_stop.config(state=tk.DISABLED)
362
-
363
- self.b_reset.config(state=tk.DISABLED)
364
-
365
- self.entry.configure(state=tk.NORMAL)
366
-
367
- self.b_30s.config(state=tk.NORMAL)
368
-
369
- self.b_1m.config(state=tk.NORMAL)
370
-
371
- self.b_90s.config(state=tk.NORMAL)
372
-
373
- self.b_2m.config(state=tk.NORMAL)
374
-
375
- self.b_3m.config(state=tk.NORMAL)
376
-
377
- self.b_4m.config(state=tk.NORMAL)
378
-
379
- self.b_5m.config(state=tk.NORMAL)
380
-
381
- self.b_6m.config(state=tk.NORMAL)
382
-
383
- self.b_10m.config(state=tk.NORMAL)
384
-
385
- self.b_20m.config(state=tk.NORMAL)
386
-
387
- self.b_30m.config(state=tk.NORMAL)
388
-
389
- self.b_1h.config(state=tk.NORMAL)
390
-
391
- self.b_start.config(state=tk.NORMAL)
392
-
393
-
394
-
395
-
396
-
397
- def exec_timer(self):
398
-
399
- if self.started:
400
-
401
- self.target_time = self.target_time - self.deltatime()
402
-
403
- self.time_set()
404
-
405
-
406
-
407
- if self.target_time <= 11:
408
-
409
- self.display.config(bg="plum")
410
-
411
-
412
-
413
- #if self.target_time == 0:
414
-
415
- #self.target_time = self.target_time + 7200
416
-
417
- #self.time_set()
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
59
  ```
436
60
 
437
61
 
@@ -452,8 +76,4 @@
452
76
 
453
77
  VS Code
454
78
 
455
- Python3.8.5
79
+ Python 3.8.5
456
-
457
-
458
-
459
- 元は他人様からコピーさせていただいたものをカスタマイズしたコードであるため、全容を把握しきれておりません。

1

タイトルと実行環境を修正しました

2021/03/07 09:54

投稿

geekmama
geekmama

スコア1

test CHANGED
@@ -1 +1 @@
1
- タイマーのマイナス時間を表示する方法につ
1
+ タイマーの残時間をマイナス表示する方法を教えてくださ
test CHANGED
@@ -450,4 +450,10 @@
450
450
 
451
451
 
452
452
 
453
+ VS Code
454
+
455
+ Python3.8.5
456
+
457
+
458
+
453
459
  元は他人様からコピーさせていただいたものをカスタマイズしたコードであるため、全容を把握しきれておりません。