回答編集履歴
5
関数名変更
answer
CHANGED
@@ -9,14 +9,14 @@
|
|
9
9
|
|
10
10
|
def each_hour(win, callback):
|
11
11
|
|
12
|
-
def
|
12
|
+
def action():
|
13
13
|
callback()
|
14
14
|
each_hour(win, callback)
|
15
15
|
|
16
16
|
now = datetime.now()
|
17
17
|
target = (now + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
|
18
18
|
delta = target - now
|
19
|
-
win.after(int(delta.total_seconds() * 1000 + 1),
|
19
|
+
win.after(int(delta.total_seconds() * 1000 + 1), action)
|
20
20
|
|
21
21
|
if __name__ == "__main__":
|
22
22
|
win = tk.Tk()
|
4
デバッグprint削除
answer
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
now = datetime.now()
|
17
17
|
target = (now + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
|
18
18
|
delta = target - now
|
19
|
-
print(delta)
|
20
19
|
win.after(int(delta.total_seconds() * 1000 + 1), repeat)
|
21
20
|
|
22
21
|
if __name__ == "__main__":
|
3
日付をまたぐときのバグ修正
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
after を使う手もありますよ。
|
2
2
|
|
3
3
|
```python
|
4
|
-
from datetime import datetime
|
4
|
+
from datetime import datetime, timedelta
|
5
5
|
import tkinter as tk
|
6
6
|
|
7
7
|
def func():
|
@@ -14,9 +14,9 @@
|
|
14
14
|
each_hour(win, callback)
|
15
15
|
|
16
16
|
now = datetime.now()
|
17
|
-
target =
|
17
|
+
target = (now + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
|
18
|
-
hour=now.hour + 1, minute=0, second=0)
|
19
18
|
delta = target - now
|
19
|
+
print(delta)
|
20
20
|
win.after(int(delta.total_seconds() * 1000 + 1), repeat)
|
21
21
|
|
22
22
|
if __name__ == "__main__":
|
2
コード修正
answer
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
target = datetime(year=now.year, month=now.month, day=now.day,
|
18
18
|
hour=now.hour + 1, minute=0, second=0)
|
19
19
|
delta = target - now
|
20
|
-
win.after(int(delta.total_seconds() + 1)
|
20
|
+
win.after(int(delta.total_seconds() * 1000 + 1), repeat)
|
21
21
|
|
22
22
|
if __name__ == "__main__":
|
23
23
|
win = tk.Tk()
|
1
関数名変更
answer
CHANGED
@@ -7,11 +7,11 @@
|
|
7
7
|
def func():
|
8
8
|
print("func")
|
9
9
|
|
10
|
-
def
|
10
|
+
def each_hour(win, callback):
|
11
11
|
|
12
12
|
def repeat():
|
13
13
|
callback()
|
14
|
-
|
14
|
+
each_hour(win, callback)
|
15
15
|
|
16
16
|
now = datetime.now()
|
17
17
|
target = datetime(year=now.year, month=now.month, day=now.day,
|
@@ -21,6 +21,6 @@
|
|
21
21
|
|
22
22
|
if __name__ == "__main__":
|
23
23
|
win = tk.Tk()
|
24
|
-
|
24
|
+
each_hour(win, func)
|
25
25
|
win.mainloop()
|
26
26
|
```
|