回答編集履歴
2
サンプルコード追加
answer
CHANGED
|
@@ -6,4 +6,35 @@
|
|
|
6
6
|
- tag_bind で "<FocusIn>" は使えませんが、
|
|
7
7
|
マウスポインタが上に来た時ならば "<Enter>" が該当します。
|
|
8
8
|
|
|
9
|
-
※ Enter キーのイベントは "<Return>"
|
|
9
|
+
※ Enter キーのイベントは "<Return>"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
----
|
|
13
|
+
追記: タグイベントの実装
|
|
14
|
+
|
|
15
|
+
最低限のサンプルです。※ Focus In/Out ではなく重複して何度もイベントが発生します。
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import tkinter as tk
|
|
19
|
+
from idlelib.redirector import WidgetRedirector
|
|
20
|
+
|
|
21
|
+
root = tk.Tk()
|
|
22
|
+
text = tk.Text(root)
|
|
23
|
+
text.grid()
|
|
24
|
+
|
|
25
|
+
def on_mark(*args):
|
|
26
|
+
pos = args[-1]
|
|
27
|
+
tags = text.tag_names(pos)
|
|
28
|
+
for name in tags:
|
|
29
|
+
text.event_generate(f"<<Tag{name.title()}Marked>>")
|
|
30
|
+
return original_mark(*args)
|
|
31
|
+
|
|
32
|
+
text.insert(tk.END, "TEST", "test")
|
|
33
|
+
text.bind("<<TagTestMarked>>", lambda e: print("TEST!"))
|
|
34
|
+
redirector = WidgetRedirector(text)
|
|
35
|
+
original_mark = redirector.register("mark", on_mark)
|
|
36
|
+
|
|
37
|
+
root.mainloop()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
参考:
|
1
補足
answer
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
> only **key**, **button**, **motion**, **enter**, **leave**, and **virtual events** may be used
|
|
2
2
|
|
|
3
|
-
問題点:
|
|
3
|
+
問題点: 上記に列挙された形式のイベントしか使えません。
|
|
4
4
|
|
|
5
5
|
- 通常のウィジェットのフォーカスイベントは "<FocusIn>" です。
|
|
6
6
|
- tag_bind で "<FocusIn>" は使えませんが、
|
|
7
|
-
マウスポインタが上に来た時ならば "<Enter>" が該当します。
|
|
7
|
+
マウスポインタが上に来た時ならば "<Enter>" が該当します。
|
|
8
|
+
|
|
9
|
+
※ Enter キーのイベントは "<Return>"
|