回答編集履歴

3

説明文の訂正

2020/05/10 03:16

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
  - スタイル名はリンク先にある表を参考に。大抵 "T" + クラス名ですが、例外有。(Treeview等)
56
56
 
57
- - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
57
+ - 上記のリンクには 'newName.oldName' と書かれています ~~が、これも反例有~~
58
58
 
59
59
  ~~"TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。~~
60
60
 

2

説明補足

2020/05/10 03:16

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -56,7 +56,9 @@
56
56
 
57
57
  - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
58
58
 
59
- "TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。
59
+ ~~"TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。~~
60
+
61
+ 解釈としては、Tabから派生したTNotebook用のTabのスタイル。
60
62
 
61
63
  - [Creating a New, Derived Style](https://tkdocs.com/tutorial/styles.html#styleoptions)
62
64
 

1

スタイルについて情報追記

2020/05/10 03:15

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -37,3 +37,73 @@
37
37
  command=self._fridayHandler)
38
38
 
39
39
  ```
40
+
41
+
42
+
43
+
44
+
45
+ ----
46
+
47
+ 追記: スタイル名のルールについては、
48
+
49
+ 公式のドキュメントでも、あまり触れられていなかったと思います。
50
+
51
+
52
+
53
+ - ttk.Label に style="TButton" のようなこともできます。(適切な用法かどうかはともかく)
54
+
55
+ - スタイル名はリンク先にある表を参考に。大抵 "T" + クラス名ですが、例外有。(Treeview等)
56
+
57
+ - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
58
+
59
+ "TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。
60
+
61
+ - [Creating a New, Derived Style](https://tkdocs.com/tutorial/styles.html#styleoptions)
62
+
63
+ tcl/tkの大元の公式ドキュメントから紹介があるのはここ。
64
+
65
+
66
+
67
+ > creating a new style (e.g. "Emergency.TButton") derived from the base style ("TButton") would be the appropriate thing to do.
68
+
69
+
70
+
71
+ 名前規則は、イメージとしては「継承」に近いです。
72
+
73
+ 例: AAA.TButton から更に派生した BBB.AAA.TButton を作成。
74
+
75
+
76
+
77
+ ```
78
+
79
+ import tkinter as tk
80
+
81
+ from tkinter import ttk
82
+
83
+
84
+
85
+ root = tk.Tk()
86
+
87
+ style = ttk.Style()
88
+
89
+
90
+
91
+ style.theme_use("clam") # TButton の背景色を簡単に変更する為
92
+
93
+ style.configure("AAA.TButton", background="black", foreground="white")
94
+
95
+ style.map("AAA.TButton", background=[("active","blue")])
96
+
97
+
98
+
99
+ # (AAA.TButton の backgroundを引継, foregroundを上書)
100
+
101
+ style.configure("BBB.AAA.TButton", foreground="yellow")
102
+
103
+
104
+
105
+ ttk.Button(root, text="HELLO", style="BBB.AAA.TButton").pack()
106
+
107
+ root.mainloop()
108
+
109
+ ```