質問編集履歴
9
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,7 +27,6 @@
|
|
27
27
|
|
28
28
|
#新規ウィンドウを作成
|
29
29
|
root = tk.Tk()
|
30
|
-
root.title("SVV測定")
|
31
30
|
root.attributes("-fullscreen", True)
|
32
31
|
|
33
32
|
|
@@ -71,12 +70,23 @@
|
|
71
70
|
interval = datetime.timedelta(milliseconds = 20)
|
72
71
|
|
73
72
|
|
74
|
-
|
75
|
-
#
|
73
|
+
#左回転時の基準時刻を取得し、press_Lに渡す
|
76
74
|
def press_L(event):
|
75
|
+
global next_time_L
|
76
|
+
next_time_L = datetime.datetime.now()
|
77
|
+
rotate_L(event)
|
78
|
+
|
79
|
+
|
80
|
+
#右回転時の基準時刻を取得し、press_Rに渡す
|
81
|
+
def press_R(event):
|
82
|
+
global next_time_R
|
83
|
+
next_time_R = datetime.datetime.now()
|
84
|
+
rotate_R(event)
|
85
|
+
|
86
|
+
|
87
|
+
def rotate_L(event):
|
77
88
|
global interval
|
78
|
-
next_time = datetime.datetime.now() + interval
|
79
|
-
|
89
|
+
global next_time_L
|
80
90
|
global img
|
81
91
|
global tkimg
|
82
92
|
global c
|
@@ -87,26 +97,19 @@
|
|
87
97
|
tkimg = ImageTk.PhotoImage(IMG)
|
88
98
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
89
99
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
100
|
+
next_time_L += interval
|
90
101
|
now = datetime.datetime.now()
|
91
|
-
delay_ms = int((next_time - now).total_seconds() * 1000)
|
102
|
+
delay_ms = int((next_time_L - now).total_seconds() * 1000)
|
92
|
-
id = root.after(delay_ms,
|
103
|
+
id = root.after(delay_ms, rotate_L, None)
|
93
104
|
def stop_L(event):
|
94
|
-
#左クリックで、左回転をストップする
|
95
105
|
root.after_cancel(id)
|
96
106
|
canvas.tag_bind("img_snow", "<ButtonPress-1>", press_L)
|
97
|
-
canvas.tag_bind("img_snow", "<ButtonPress-3>", press_R)
|
98
|
-
def stop_L_by_R(event):
|
99
|
-
#右クリックでも、左回転をストップする
|
100
|
-
root.after_cancel(id)
|
101
|
-
canvas.tag_bind("img_snow", "<ButtonPress-3>", press_R)
|
102
|
-
canvas.
|
107
|
+
canvas.bind("<ButtonRelease-1>", stop_L)
|
103
|
-
|
108
|
+
|
104
|
-
|
105
|
-
|
109
|
+
|
106
|
-
def
|
110
|
+
def rotate_R(event):
|
107
111
|
global interval
|
108
|
-
next_time = datetime.datetime.now() + interval
|
109
|
-
|
112
|
+
global next_time_R
|
110
113
|
global img
|
111
114
|
global tkimg
|
112
115
|
global c
|
@@ -117,20 +120,14 @@
|
|
117
120
|
tkimg = ImageTk.PhotoImage(IMG)
|
118
121
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
119
122
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
123
|
+
next_time_R += interval
|
120
124
|
now = datetime.datetime.now()
|
121
|
-
delay_ms = int((next_time - now).total_seconds() * 1000)
|
125
|
+
delay_ms = int((next_time_R - now).total_seconds() * 1000)
|
122
|
-
id = root.after(delay_ms,
|
126
|
+
id = root.after(delay_ms, rotate_R, None)
|
123
127
|
def stop_R(event):
|
124
|
-
#右クリックで、右回転をストップする
|
125
128
|
root.after_cancel(id)
|
126
129
|
canvas.tag_bind("img_snow", "<ButtonPress-3>", press_R)
|
127
|
-
canvas.tag_bind("img_snow", "<ButtonPress-1>", press_L)
|
128
|
-
def stop_R_by_L(event):
|
129
|
-
#左クリックでも、右回転をストップする
|
130
|
-
root.after_cancel(id)
|
131
|
-
canvas.tag_bind("img_snow", "<ButtonPress-1>", press_L)
|
132
|
-
canvas.
|
130
|
+
canvas.bind("<ButtonRelease-3>", stop_R)
|
133
|
-
canvas.tag_bind("img_snow", "<ButtonPress-1>", stop_R_by_L)
|
134
131
|
|
135
132
|
|
136
133
|
def finish(event):
|
8
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -69,6 +69,7 @@
|
|
69
69
|
|
70
70
|
#角速度の指定
|
71
71
|
interval = datetime.timedelta(milliseconds = 20)
|
72
|
+
|
72
73
|
|
73
74
|
|
74
75
|
#イベントが発生したときの処理
|
@@ -79,9 +80,10 @@
|
|
79
80
|
global img
|
80
81
|
global tkimg
|
81
82
|
global c
|
82
|
-
c = c +
|
83
|
+
c = c + 1
|
84
|
+
R = c / 10
|
83
85
|
canvas.delete("all")
|
84
|
-
IMG = img.rotate(
|
86
|
+
IMG = img.rotate(R, resample = Image.BICUBIC)
|
85
87
|
tkimg = ImageTk.PhotoImage(IMG)
|
86
88
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
87
89
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
@@ -108,9 +110,10 @@
|
|
108
110
|
global img
|
109
111
|
global tkimg
|
110
112
|
global c
|
111
|
-
c = c -
|
113
|
+
c = c - 1
|
114
|
+
R = c / 10
|
112
115
|
canvas.delete("all")
|
113
|
-
IMG = img.rotate(
|
116
|
+
IMG = img.rotate(R, resample = Image.BICUBIC)
|
114
117
|
tkimg = ImageTk.PhotoImage(IMG)
|
115
118
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
116
119
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
@@ -133,7 +136,7 @@
|
|
133
136
|
def finish(event):
|
134
137
|
#Enterキーを押すことで全画面表示を終了し、回転角度を取得する
|
135
138
|
root.destroy()
|
136
|
-
print(-c)
|
139
|
+
print(-c / 10)
|
137
140
|
|
138
141
|
|
139
142
|
#左クリックで呼び出すイベント
|
@@ -150,6 +153,9 @@
|
|
150
153
|
|
151
154
|
#メインループ
|
152
155
|
root.mainloop()
|
156
|
+
|
157
|
+
|
158
|
+
#end.
|
153
159
|
|
154
160
|
```
|
155
161
|
|
7
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,22 +102,21 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
def press_R(event):
|
105
|
-
global
|
105
|
+
global interval
|
106
|
-
|
106
|
+
next_time = datetime.datetime.now() + interval
|
107
107
|
#右クリックの回数によって、右回転させる
|
108
108
|
global img
|
109
109
|
global tkimg
|
110
110
|
global c
|
111
|
-
global lt_r
|
112
|
-
c = c - 0.
|
111
|
+
c = c - 0.1
|
113
112
|
canvas.delete("all")
|
114
113
|
IMG = img.rotate(c, resample = Image.BICUBIC)
|
115
114
|
tkimg = ImageTk.PhotoImage(IMG)
|
116
115
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
117
116
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
118
|
-
|
117
|
+
now = datetime.datetime.now()
|
119
|
-
|
118
|
+
delay_ms = int((next_time - now).total_seconds() * 1000)
|
120
|
-
id = root.after(
|
119
|
+
id = root.after(delay_ms, press_R, None)
|
121
120
|
def stop_R(event):
|
122
121
|
#右クリックで、右回転をストップする
|
123
122
|
root.after_cancel(id)
|
@@ -194,7 +193,7 @@
|
|
194
193
|
#---透明なpng画像の作成---
|
195
194
|
|
196
195
|
#画像サイズの指定
|
197
|
-
WIDTH = 1
|
196
|
+
WIDTH = 1600
|
198
197
|
HEIGHT = 1000
|
199
198
|
|
200
199
|
|
6
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,21 +67,27 @@
|
|
67
67
|
c = 0
|
68
68
|
|
69
69
|
|
70
|
+
#角速度の指定
|
71
|
+
interval = datetime.timedelta(milliseconds = 20)
|
72
|
+
|
73
|
+
|
70
74
|
#イベントが発生したときの処理
|
71
75
|
def press_L(event):
|
76
|
+
global interval
|
72
|
-
|
77
|
+
next_time = datetime.datetime.now() + interval
|
73
78
|
#左クリックの回数によって、左回転させる
|
74
79
|
global img
|
75
80
|
global tkimg
|
76
81
|
global c
|
77
82
|
c = c + 0.1
|
78
|
-
canvas.delete("all")
|
83
|
+
canvas.delete("all")
|
79
84
|
IMG = img.rotate(c, resample = Image.BICUBIC)
|
80
85
|
tkimg = ImageTk.PhotoImage(IMG)
|
81
86
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
82
87
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
83
|
-
|
88
|
+
now = datetime.datetime.now()
|
89
|
+
delay_ms = int((next_time - now).total_seconds() * 1000)
|
84
|
-
id = root.after(
|
90
|
+
id = root.after(delay_ms, press_L, None)
|
85
91
|
def stop_L(event):
|
86
92
|
#左クリックで、左回転をストップする
|
87
93
|
root.after_cancel(id)
|
@@ -96,17 +102,22 @@
|
|
96
102
|
|
97
103
|
|
98
104
|
def press_R(event):
|
105
|
+
global bt_r
|
106
|
+
bt_r = time.time()
|
99
107
|
#右クリックの回数によって、右回転させる
|
100
108
|
global img
|
101
109
|
global tkimg
|
102
110
|
global c
|
111
|
+
global lt_r
|
103
|
-
c = c - 0.
|
112
|
+
c = c - 0.2
|
104
|
-
canvas.delete("all")
|
113
|
+
canvas.delete("all")
|
105
114
|
IMG = img.rotate(c, resample = Image.BICUBIC)
|
106
115
|
tkimg = ImageTk.PhotoImage(IMG)
|
107
116
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
108
117
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
118
|
+
lt_r = time.time()
|
119
|
+
it = round((lt_r - bt_r)*1000)
|
109
|
-
id = root.after(
|
120
|
+
id = root.after(40 - it, press_R, None)
|
110
121
|
def stop_R(event):
|
111
122
|
#右クリックで、右回転をストップする
|
112
123
|
root.after_cancel(id)
|
5
コードの時刻表示部分を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
```python
|
23
23
|
import tkinter as tk
|
24
24
|
from PIL import Image, ImageTk
|
25
|
+
import datetime
|
25
26
|
|
26
27
|
|
27
28
|
#新規ウィンドウを作成
|
@@ -68,6 +69,7 @@
|
|
68
69
|
|
69
70
|
#イベントが発生したときの処理
|
70
71
|
def press_L(event):
|
72
|
+
bt = datetime.datetime() ##追加
|
71
73
|
#左クリックの回数によって、左回転させる
|
72
74
|
global img
|
73
75
|
global tkimg
|
@@ -78,7 +80,8 @@
|
|
78
80
|
tkimg = ImageTk.PhotoImage(IMG)
|
79
81
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
80
82
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
83
|
+
lt = datetime.datetime() ##追加
|
81
|
-
id = root.after(20, press_L, None)
|
84
|
+
id = root.after(20 - print(lt - bt), press_L, None) ##追加
|
82
85
|
def stop_L(event):
|
83
86
|
#左クリックで、左回転をストップする
|
84
87
|
root.after_cancel(id)
|
4
タイトルを修正しました。(操作 → 動作)
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
afterメソッドで、正確に「任意秒ごと」に
|
1
|
+
afterメソッドで、正確に「任意秒ごと」に動作させたい。
|
test
CHANGED
File without changes
|
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,12 +72,13 @@
|
|
72
72
|
global img
|
73
73
|
global tkimg
|
74
74
|
global c
|
75
|
-
c = c + 0.
|
75
|
+
c = c + 0.1
|
76
|
+
canvas.delete("all") ##追加
|
76
77
|
IMG = img.rotate(c, resample = Image.BICUBIC)
|
77
78
|
tkimg = ImageTk.PhotoImage(IMG)
|
78
79
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
79
80
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
80
|
-
id = root.after(
|
81
|
+
id = root.after(20, press_L, None)
|
81
82
|
def stop_L(event):
|
82
83
|
#左クリックで、左回転をストップする
|
83
84
|
root.after_cancel(id)
|
@@ -96,12 +97,13 @@
|
|
96
97
|
global img
|
97
98
|
global tkimg
|
98
99
|
global c
|
99
|
-
c = c - 0.
|
100
|
+
c = c - 0.1
|
101
|
+
canvas.delete("all") ##追加
|
100
102
|
IMG = img.rotate(c, resample = Image.BICUBIC)
|
101
103
|
tkimg = ImageTk.PhotoImage(IMG)
|
102
104
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
103
105
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
104
|
-
id = root.after(
|
106
|
+
id = root.after(20, press_R, None)
|
105
107
|
def stop_R(event):
|
106
108
|
#右クリックで、右回転をストップする
|
107
109
|
root.after_cancel(id)
|
2
コードを修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,25 +24,25 @@
|
|
24
24
|
from PIL import Image, ImageTk
|
25
25
|
|
26
26
|
|
27
|
-
#画面サイズの指定
|
28
|
-
WIDTH = 1300
|
29
|
-
HEIGHT = 800
|
30
|
-
|
31
|
-
|
32
27
|
#新規ウィンドウを作成
|
33
28
|
root = tk.Tk()
|
34
29
|
root.title("SVV測定")
|
35
30
|
root.attributes("-fullscreen", True)
|
36
31
|
|
37
32
|
|
33
|
+
#画面サイズの指定
|
34
|
+
WIDTH = root.winfo_screenwidth()
|
35
|
+
HEIGHT = root.winfo_screenheight()
|
36
|
+
|
37
|
+
|
38
38
|
#ウィンドウ上にフレームを作成
|
39
39
|
frame = tk.Frame(root)
|
40
|
-
frame.pac
|
40
|
+
frame.place(x = -5, y = -5, width = WIDTH + 10, height = HEIGHT + 10)
|
41
41
|
|
42
42
|
|
43
43
|
#フレーム上に、キャンバスを作成
|
44
44
|
canvas = tk.Canvas(frame, width = WIDTH, height = HEIGHT, bg = "black")
|
45
|
-
canvas.pac
|
45
|
+
canvas.place(x = 0, y = 0, width = WIDTH + 10, height = HEIGHT + 10)
|
46
46
|
|
47
47
|
|
48
48
|
#画像のプリセット角を"cs"として定義
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,7 +37,6 @@
|
|
37
37
|
|
38
38
|
#ウィンドウ上にフレームを作成
|
39
39
|
frame = tk.Frame(root)
|
40
|
-
#frame = tk.Frame(root, width = root.winfo_screenwidth(), height = root.winfo_screenheight(), bg = "green")
|
41
40
|
frame.pack()
|
42
41
|
|
43
42
|
|
@@ -74,7 +73,7 @@
|
|
74
73
|
global tkimg
|
75
74
|
global c
|
76
75
|
c = c + 0.005
|
77
|
-
IMG = img.rotate(c)
|
76
|
+
IMG = img.rotate(c, resample = Image.BICUBIC)
|
78
77
|
tkimg = ImageTk.PhotoImage(IMG)
|
79
78
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
80
79
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|
@@ -98,7 +97,7 @@
|
|
98
97
|
global tkimg
|
99
98
|
global c
|
100
99
|
c = c - 0.005
|
101
|
-
IMG = img.rotate(c)
|
100
|
+
IMG = img.rotate(c, resample = Image.BICUBIC)
|
102
101
|
tkimg = ImageTk.PhotoImage(IMG)
|
103
102
|
canvas.create_image(WIDTH/2, HEIGHT/2, image = tkimg, anchor = "center", tags = "img")
|
104
103
|
canvas.create_image(WIDTH/2, HEIGHT/2, image=tkimg_snow, anchor = "center", tags="img_snow")
|