回答編集履歴

5

けしたとおもったらけしてなかった

2018/04/13 13:33

投稿

toritoritorina
toritoritorina

スコア972

test CHANGED
@@ -26,13 +26,15 @@
26
26
 
27
27
  for x in range(10):
28
28
 
29
- # gridを後で呼ぶようにし、Buttonオブジェクトをそれぞれリストに入れます。
29
+ # Buttonオブジェクトを、一度変数に入れておきます。
30
30
 
31
31
  button = tk.Button(
32
32
 
33
33
  self, text='{0}{1}'.format(y, x), font=('Helvetica', 20)
34
34
 
35
35
  )
36
+
37
+ # 配置します。
36
38
 
37
39
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
38
40
 

4

リストいりませんでしたわ

2018/04/13 13:33

投稿

toritoritorina
toritoritorina

スコア972

test CHANGED
@@ -16,8 +16,6 @@
16
16
 
17
17
  super(Gui, self).__init__(master)
18
18
 
19
- self.buttons = []
20
-
21
19
  self.create_widget()
22
20
 
23
21
 
@@ -35,8 +33,6 @@
35
33
  self, text='{0}{1}'.format(y, x), font=('Helvetica', 20)
36
34
 
37
35
  )
38
-
39
- self.buttons.append(button)
40
36
 
41
37
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
42
38
 

3

しゅうせい

2018/04/13 13:31

投稿

toritoritorina
toritoritorina

スコア972

test CHANGED
@@ -70,8 +70,6 @@
70
70
 
71
71
  def change_color(self, event):
72
72
 
73
- """F1で呼ばれる、ボタンの色を変えるメソッド"""
74
-
75
73
  # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。k
76
74
 
77
75
  # bgの部分は、text等にもできます。

2

しゅうせい

2018/04/13 13:30

投稿

toritoritorina
toritoritorina

スコア972

test CHANGED
File without changes

1

しゅうせい

2018/04/13 13:30

投稿

toritoritorina
toritoritorina

スコア972

test CHANGED
@@ -40,6 +40,8 @@
40
40
 
41
41
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
42
42
 
43
+ # それぞれのボタンを押したら、change_colorメソッドが呼ばれます。
44
+
43
45
  button.bind('<Button-1>', self.change_color)
44
46
 
45
47
 
@@ -70,7 +72,7 @@
70
72
 
71
73
  """F1で呼ばれる、ボタンの色を変えるメソッド"""
72
74
 
73
- # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。
75
+ # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。k
74
76
 
75
77
  # bgの部分は、text等にもできます。
76
78