質問編集履歴

3

ソースコードの追加

2019/11/25 06:51

投稿

kemomimi_sabal
kemomimi_sabal

スコア12

test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,125 @@
9
9
  Canvasのオブジェクトをすべて取得して、座標を取得しその座標を使って計算したいです
10
10
 
11
11
  y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。
12
+
13
+
14
+
15
+ ```Python
16
+
17
+ def drawKeys(self):
18
+
19
+ measure_height = 20
20
+
21
+ t_measure_height = measure_height * 12
22
+
23
+
24
+
25
+ half = measure_height / 2
26
+
27
+ print(measure_height * 11 - half + (t_measure_height * 7))
28
+
29
+ outline = "#000"
30
+
31
+ black = "#333"
32
+
33
+ white = "#fff"
34
+
35
+
36
+
37
+ for i in range(0, 7):
38
+
39
+ self.pianoKeysCanvas.create_rectangle(0, 0 + (t_measure_height * i), 120,
40
+
41
+ measure_height + half + (t_measure_height * i), fill=white,
42
+
43
+ outline=outline)
44
+
45
+ self.pianoKeysCanvas.create_rectangle(0, measure_height + half + (t_measure_height * i), 120,
46
+
47
+ measure_height * 4 - half + (t_measure_height * i), fill=white,
48
+
49
+ outline=outline)
50
+
51
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 4 - half + (t_measure_height * i), 120,
52
+
53
+ measure_height * 6 - half + (t_measure_height * i), fill=white,
54
+
55
+ outline=outline)
56
+
57
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 6 - half + (t_measure_height * i), 120,
58
+
59
+ measure_height * 7 + (t_measure_height * i), fill=white,
60
+
61
+ outline=outline)
62
+
63
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 7 + (t_measure_height * i), 120,
64
+
65
+ measure_height * 9 - half + (t_measure_height * i), fill=white,
66
+
67
+ outline=outline)
68
+
69
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 9 - half + (t_measure_height * i), 120,
70
+
71
+ measure_height * 11 - half + (t_measure_height * i), fill=white,
72
+
73
+ outline=outline)
74
+
75
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 11 - half + (t_measure_height * i), 120,
76
+
77
+ measure_height * 12 + (t_measure_height * i), fill=white,
78
+
79
+ outline=outline, tags="rectangle")
80
+
81
+
82
+
83
+ self.pianoKeysCanvas.create_rectangle(0, measure_height + (t_measure_height * i), 60,
84
+
85
+ measure_height * 2 + (t_measure_height * i), fill=black,
86
+
87
+ outline=outline)
88
+
89
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 3 + (t_measure_height * i), 60,
90
+
91
+ measure_height * 4 + (t_measure_height * i), fill=black,
92
+
93
+ outline=outline)
94
+
95
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 5 + (t_measure_height * i), 60,
96
+
97
+ measure_height * 6 + (t_measure_height * i), fill=black,
98
+
99
+ outline=outline)
100
+
101
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 8 + (t_measure_height * i), 60,
102
+
103
+ measure_height * 9 + (t_measure_height * i), fill=black,
104
+
105
+ outline=outline)
106
+
107
+ self.pianoKeysCanvas.create_rectangle(0, measure_height * 10 + (t_measure_height * i), 60,
108
+
109
+ measure_height * 11 + (t_measure_height * i), fill=black,
110
+
111
+ outline=outline)
112
+
113
+
114
+
115
+ self.pianoKeysCanvas.create_text(90, measure_height * 11 + half + (t_measure_height * i),
116
+
117
+ text="C" + str(7 - i))
118
+
119
+ for id in self.pianoKeysCanvas.find_all(): # 全オブジェクトを列挙
120
+
121
+ tag = self.pianoKeysCanvas.itemcget(id, 'tags') # タグ名を取得
122
+
123
+ print(tag)
124
+
125
+ if tag.startswith('rectangle'):
126
+
127
+ self.List_white = (self.pianoKeysCanvas.coords(id)) # .coordsで座標を取得
128
+
129
+ print('White key y', self.List_white[1])
130
+
131
+ ```
132
+
133
+ ソースは上記です。

2

詳細な説明の追加

2019/11/25 06:51

投稿

kemomimi_sabal
kemomimi_sabal

スコア12

test CHANGED
File without changes
test CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- Tkinterを使っています。
5
+ python3のTkinterを使っています。
6
6
 
7
7
 
8
8
 
9
+ Canvasのオブジェクトをすべて取得して、座標を取得しその座標を使って計算したいです
10
+
9
11
  y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。

1

説明の追加

2019/11/22 08:12

投稿

kemomimi_sabal
kemomimi_sabal

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1 +1,9 @@
1
- pythonでピアノロールのy座標からノート番号を計算したいのですが、やり方がわかりません。どなたか教えてくださいませんか
1
+ pythonでピアノロールのy座標からノート番号を計算したいのですが、やり方がわかりません。どなたか教えてくださいませんか
2
+
3
+
4
+
5
+ Tkinterを使っています。
6
+
7
+
8
+
9
+ y / ノートの高さの単位で求まる(10単位なら10)と教わったのですが、どうもうまくいきません。