回答編集履歴

3

コード例を追記

2022/12/09 21:07

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -20,3 +20,15 @@
20
20
  `<Button-1>` の bind ではなく、Button の command 内で relief を変更する。
21
21
  デフォルトの挙動を行った後の relief 変更なので、デフォルト挙動の影響を受けない。
22
22
  (※ command では event は引数に渡らないので、button のインスタンスを functools.partial 等で渡します)
23
+
24
+ ```python
25
+ # 事前に import
26
+ from functools import partial
27
+ from types import SimpleNamespace
28
+
29
+ ...
30
+
31
+ # event の代わりに event.widget 部分に button を格納した名前空間を渡す
32
+ button.config(command=partial(type_select, SimpleNamespace(widget=button)))
33
+
34
+ ```

2

他の解決策に言及

2022/12/09 21:04

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -15,3 +15,8 @@
15
15
  Button の command に設定した関数は呼ばれなくなります。
16
16
  (デフォルトの挙動をキャンセルする為)
17
17
 
18
+
19
+ 他の解決策
20
+ `<Button-1>` の bind ではなく、Button の command 内で relief を変更する。
21
+ デフォルトの挙動を行った後の relief 変更なので、デフォルト挙動の影響を受けない。
22
+ (※ command では event は引数に渡らないので、button のインスタンスを functools.partial 等で渡します)

1

確認できなかったため、一旦取り下げ

2022/12/09 20:58

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -15,8 +15,3 @@
15
15
  Button の command に設定した関数は呼ばれなくなります。
16
16
  (デフォルトの挙動をキャンセルする為)
17
17
 
18
- 他の解決策
19
- `f relief == "raised":` による判別が、
20
- デフォルトの挙動に影響されるというのが、現状の実装方法の問題点です。
21
- Button のサブクラスを作り、toggle の状態を独自の変数に管理することでも回避できます。
22
-