質問編集履歴
3
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,4 +3,65 @@
|
|
3
3
|
python3のTkinterを使っています。
|
4
4
|
|
5
5
|
Canvasのオブジェクトをすべて取得して、座標を取得しその座標を使って計算したいです
|
6
|
-
y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。
|
6
|
+
y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。
|
7
|
+
|
8
|
+
```Python
|
9
|
+
def drawKeys(self):
|
10
|
+
measure_height = 20
|
11
|
+
t_measure_height = measure_height * 12
|
12
|
+
|
13
|
+
half = measure_height / 2
|
14
|
+
print(measure_height * 11 - half + (t_measure_height * 7))
|
15
|
+
outline = "#000"
|
16
|
+
black = "#333"
|
17
|
+
white = "#fff"
|
18
|
+
|
19
|
+
for i in range(0, 7):
|
20
|
+
self.pianoKeysCanvas.create_rectangle(0, 0 + (t_measure_height * i), 120,
|
21
|
+
measure_height + half + (t_measure_height * i), fill=white,
|
22
|
+
outline=outline)
|
23
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height + half + (t_measure_height * i), 120,
|
24
|
+
measure_height * 4 - half + (t_measure_height * i), fill=white,
|
25
|
+
outline=outline)
|
26
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 4 - half + (t_measure_height * i), 120,
|
27
|
+
measure_height * 6 - half + (t_measure_height * i), fill=white,
|
28
|
+
outline=outline)
|
29
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 6 - half + (t_measure_height * i), 120,
|
30
|
+
measure_height * 7 + (t_measure_height * i), fill=white,
|
31
|
+
outline=outline)
|
32
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 7 + (t_measure_height * i), 120,
|
33
|
+
measure_height * 9 - half + (t_measure_height * i), fill=white,
|
34
|
+
outline=outline)
|
35
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 9 - half + (t_measure_height * i), 120,
|
36
|
+
measure_height * 11 - half + (t_measure_height * i), fill=white,
|
37
|
+
outline=outline)
|
38
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 11 - half + (t_measure_height * i), 120,
|
39
|
+
measure_height * 12 + (t_measure_height * i), fill=white,
|
40
|
+
outline=outline, tags="rectangle")
|
41
|
+
|
42
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height + (t_measure_height * i), 60,
|
43
|
+
measure_height * 2 + (t_measure_height * i), fill=black,
|
44
|
+
outline=outline)
|
45
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 3 + (t_measure_height * i), 60,
|
46
|
+
measure_height * 4 + (t_measure_height * i), fill=black,
|
47
|
+
outline=outline)
|
48
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 5 + (t_measure_height * i), 60,
|
49
|
+
measure_height * 6 + (t_measure_height * i), fill=black,
|
50
|
+
outline=outline)
|
51
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 8 + (t_measure_height * i), 60,
|
52
|
+
measure_height * 9 + (t_measure_height * i), fill=black,
|
53
|
+
outline=outline)
|
54
|
+
self.pianoKeysCanvas.create_rectangle(0, measure_height * 10 + (t_measure_height * i), 60,
|
55
|
+
measure_height * 11 + (t_measure_height * i), fill=black,
|
56
|
+
outline=outline)
|
57
|
+
|
58
|
+
self.pianoKeysCanvas.create_text(90, measure_height * 11 + half + (t_measure_height * i),
|
59
|
+
text="C" + str(7 - i))
|
60
|
+
for id in self.pianoKeysCanvas.find_all(): # 全オブジェクトを列挙
|
61
|
+
tag = self.pianoKeysCanvas.itemcget(id, 'tags') # タグ名を取得
|
62
|
+
print(tag)
|
63
|
+
if tag.startswith('rectangle'):
|
64
|
+
self.List_white = (self.pianoKeysCanvas.coords(id)) # .coordsで座標を取得
|
65
|
+
print('White key y', self.List_white[1])
|
66
|
+
```
|
67
|
+
ソースは上記です。
|
2
詳細な説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
pythonでピアノロールのy座標からノート番号を計算したいのですが、やり方がわかりません。どなたか教えてくださいませんか。
|
2
2
|
|
3
|
-
Tkinterを使っています。
|
3
|
+
python3のTkinterを使っています。
|
4
4
|
|
5
|
+
Canvasのオブジェクトをすべて取得して、座標を取得しその座標を使って計算したいです
|
5
6
|
y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。
|
1
説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,5 @@
|
|
1
|
-
pythonでピアノロールのy座標からノート番号を計算したいのですが、やり方がわかりません。どなたか教えてくださいませんか
|
1
|
+
pythonでピアノロールのy座標からノート番号を計算したいのですが、やり方がわかりません。どなたか教えてくださいませんか。
|
2
|
+
|
3
|
+
Tkinterを使っています。
|
4
|
+
|
5
|
+
y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。
|