回答編集履歴
3
スクリーンショットを掲載
answer
CHANGED
@@ -75,5 +75,6 @@
|
|
75
75
|
parent = tree.insert("", tk.END, text="parent", tags="item")
|
76
76
|
child = tree.insert(parent, tk.END, text="child", tags="item")
|
77
77
|
root.mainloop()
|
78
|
+
```
|
78
79
|
|
79
|
-
|
80
|
+

|
2
サンプルコードを追加
answer
CHANGED
@@ -19,4 +19,61 @@
|
|
19
19
|
-background {disabled SystemButtonFace \
|
20
20
|
selected SystemHighlight}
|
21
21
|
''')
|
22
|
+
```
|
23
|
+
|
24
|
+
----
|
25
|
+
|
26
|
+
```python
|
27
|
+
#!/usr/bin/env python
|
28
|
+
|
29
|
+
import tkinter as tk
|
30
|
+
from tkinter import ttk
|
31
|
+
|
32
|
+
root = tk.Tk()
|
33
|
+
style = ttk.Style()
|
34
|
+
|
35
|
+
# 注意点: theme によって有効・無効になるスタイルがあります。
|
36
|
+
# 例えば、このコードの場合は、theem_use("default") にすると
|
37
|
+
# ttk.Frame 枠線の色が変わります。
|
38
|
+
style.theme_use("clam")
|
39
|
+
|
40
|
+
# 不具合対応パッチ
|
41
|
+
root.tk.eval("""
|
42
|
+
ttk::style map Treeview \
|
43
|
+
-foreground {disabled SystemGrayText \
|
44
|
+
selected SystemHighlightText} \
|
45
|
+
-background {disabled SystemButtonFace \
|
46
|
+
selected SystemHighlight}
|
47
|
+
""")
|
48
|
+
|
49
|
+
style.configure("Treeview",
|
50
|
+
background="#eeeeff",
|
51
|
+
fieldbackground="#eeeeff",
|
52
|
+
# NOTE: Treeview にも border オプションはありますが、
|
53
|
+
# theme によって挙動が異なる為、目的の用途にはほぼ使えません。
|
54
|
+
borderwidth=0,
|
55
|
+
)
|
56
|
+
style.configure("Treeview.Heading",
|
57
|
+
background="#aaaaff",
|
58
|
+
borderwidth=0,
|
59
|
+
)
|
60
|
+
style.configure("Tree.TFrame",
|
61
|
+
# ttk.Frame の場合、widget のオプションと,
|
62
|
+
# style のオプション両方で指定します。
|
63
|
+
# ここも theme 次第では挙動が変わります。
|
64
|
+
background="#aaaaff")
|
65
|
+
|
66
|
+
## 外枠線の為に Frame を生成。
|
67
|
+
#frame = tk.Frame(root, bd=4, bg="#aaaaff")
|
68
|
+
frame = ttk.Frame(root, style="Tree.TFrame",
|
69
|
+
borderwidth=4, relief='solid')
|
70
|
+
frame.pack()
|
71
|
+
|
72
|
+
tree = ttk.Treeview(frame) # NOTE: 外枠の為に、親クラスにFrameを設定。
|
73
|
+
tree.pack()
|
74
|
+
tree.tag_configure("item", background="#eeeeff")
|
75
|
+
parent = tree.insert("", tk.END, text="parent", tags="item")
|
76
|
+
child = tree.insert(parent, tk.END, text="child", tags="item")
|
77
|
+
root.mainloop()
|
78
|
+
|
22
79
|
```
|
1
修正: 紛らわしいかもしれないので不要な情報を削除
answer
CHANGED
@@ -19,40 +19,4 @@
|
|
19
19
|
-background {disabled SystemButtonFace \
|
20
20
|
selected SystemHighlight}
|
21
21
|
''')
|
22
|
-
```
|
23
|
-
|
24
|
-
----
|
25
|
-
```python
|
26
|
-
|
27
|
-
def fixture_treeview_tag_config(style):
|
28
|
-
# NOTE: https://bugs.python.org/issue36468
|
29
|
-
def fixed_map(option):
|
30
|
-
# Fix for setting text colour for Tkinter 8.6.9
|
31
|
-
# From: https://core.tcl.tk/tk/info/509cafafae
|
32
|
-
#
|
33
|
-
# Returns the style map for 'option' with any styles starting with
|
34
|
-
# ('!disabled', '!selected', ...) filtered out.
|
35
|
-
|
36
|
-
# style.map() returns an empty list for missing options, so this
|
37
|
-
# should be future-safe.
|
38
|
-
return [elm for elm in style.map('Treeview', query_opt=option) if
|
39
|
-
elm[:2] != ('!disabled', '!selected')]
|
40
|
-
|
41
|
-
style.map('Treeview',
|
42
|
-
foreground=fixed_map('foreground'),
|
43
|
-
background=fixed_map('background'))
|
44
|
-
|
45
|
-
# Remove dot focus on "#0" column
|
46
|
-
style.layout('Treeview.Item',
|
47
|
-
[('Treeitem.padding',
|
48
|
-
{'children': [('Treeitem.indicator', {'side': 'left', 'sticky': ''}),
|
49
|
-
('Treeitem.image', {'side': 'left', 'sticky': ''}),
|
50
|
-
('Treeitem.text', {'side': 'left', 'sticky': ''})],
|
51
|
-
'sticky': 'nswe'})])
|
52
|
-
|
53
|
-
|
54
|
-
# main側で呼び出し
|
55
|
-
|
56
|
-
fixture_treevbiew_tag_config(ttk.Style())
|
57
|
-
|
58
22
|
```
|