回答編集履歴
1
サンプルコード追加
test
CHANGED
@@ -7,3 +7,61 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
`treeview.selection_toggle(*treeview.selection())` で解除できます。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
----
|
14
|
+
|
15
|
+
```python
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
import tkinter as tk
|
20
|
+
|
21
|
+
from tkinter import ttk
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
root = tk.Tk()
|
26
|
+
|
27
|
+
tree = ttk.Treeview(root, show="headings", columns=[1], selectmode="browse")
|
28
|
+
|
29
|
+
tree.pack(fill=tk.BOTH, expand=True)
|
30
|
+
|
31
|
+
for num in range(10):
|
32
|
+
|
33
|
+
tree.insert("", tk.END, values=[num])
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
ctrl = tk.BooleanVar(tree)
|
38
|
+
|
39
|
+
def unselect(event=None):
|
40
|
+
|
41
|
+
if event and not ctrl.get():
|
42
|
+
|
43
|
+
return
|
44
|
+
|
45
|
+
#for item in tree.selection():
|
46
|
+
|
47
|
+
# tree.selection_toggle(item)
|
48
|
+
|
49
|
+
tree.selection_toggle(*tree.selection())
|
50
|
+
|
51
|
+
ctrl.set(0)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
tree.bind("<Control-1>", lambda e: ctrl.set(1))
|
56
|
+
|
57
|
+
tree.bind("<<TreeviewSelect>>", unselect)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
ttk.Button(root, text="unselect", command=unselect).pack()
|
62
|
+
|
63
|
+
root.mainloop()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```
|