teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

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

2018/04/13 13:33

投稿

toritoritorina
toritoritorina

スコア972

answer CHANGED
@@ -12,10 +12,11 @@
12
12
  def create_widget(self):
13
13
  for y in range(10):
14
14
  for x in range(10):
15
- # gridを後で呼ぶようにし、Buttonオブジェクトをそれぞれリストに入れます。
15
+ # Buttonオブジェクトを、一度変数に入れておきます。
16
16
  button = tk.Button(
17
17
  self, text='{0}{1}'.format(y, x), font=('Helvetica', 20)
18
18
  )
19
+ # 配置します。
19
20
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
20
21
  # それぞれのボタンを押したら、change_colorメソッドが呼ばれます。
21
22
  button.bind('<Button-1>', self.change_color)

4

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

2018/04/13 13:33

投稿

toritoritorina
toritoritorina

スコア972

answer CHANGED
@@ -7,7 +7,6 @@
7
7
 
8
8
  def __init__(self, master=None):
9
9
  super(Gui, self).__init__(master)
10
- self.buttons = []
11
10
  self.create_widget()
12
11
 
13
12
  def create_widget(self):
@@ -17,7 +16,6 @@
17
16
  button = tk.Button(
18
17
  self, text='{0}{1}'.format(y, x), font=('Helvetica', 20)
19
18
  )
20
- self.buttons.append(button)
21
19
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
22
20
  # それぞれのボタンを押したら、change_colorメソッドが呼ばれます。
23
21
  button.bind('<Button-1>', self.change_color)

3

しゅうせい

2018/04/13 13:31

投稿

toritoritorina
toritoritorina

スコア972

answer CHANGED
@@ -34,7 +34,6 @@
34
34
  self.master.rowconfigure(0, weight=1)
35
35
 
36
36
  def change_color(self, event):
37
- """F1で呼ばれる、ボタンの色を変えるメソッド"""
38
37
  # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。k
39
38
  # bgの部分は、text等にもできます。
40
39
  event.widget['bg'] = 'white'

2

しゅうせい

2018/04/13 13:30

投稿

toritoritorina
toritoritorina

スコア972

answer CHANGED
File without changes

1

しゅうせい

2018/04/13 13:30

投稿

toritoritorina
toritoritorina

スコア972

answer CHANGED
@@ -19,6 +19,7 @@
19
19
  )
20
20
  self.buttons.append(button)
21
21
  button.grid(column=x, row=y, sticky=('N', 'S', 'E', 'W'))
22
+ # それぞれのボタンを押したら、change_colorメソッドが呼ばれます。
22
23
  button.bind('<Button-1>', self.change_color)
23
24
 
24
25
  self.grid(column=0, row=0, sticky=('N', 'S', 'E', 'W'))
@@ -34,7 +35,7 @@
34
35
 
35
36
  def change_color(self, event):
36
37
  """F1で呼ばれる、ボタンの色を変えるメソッド"""
37
- # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。
38
+ # 押されたボタン等のウィジェットには、event.widgetでアクセスできます。k
38
39
  # bgの部分は、text等にもできます。
39
40
  event.widget['bg'] = 'white'
40
41