teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

説明文の訂正

2020/05/10 03:16

投稿

teamikl
teamikl

スコア8817

answer CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  - ttk.Label に style="TButton" のようなこともできます。(適切な用法かどうかはともかく)
28
28
  - スタイル名はリンク先にある表を参考に。大抵 "T" + クラス名ですが、例外有。(Treeview等)
29
- - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
29
+ - 上記のリンクには 'newName.oldName' と書かれています ~~が、これも反例有~~
30
30
  ~~"TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。~~
31
31
  解釈としては、Tabから派生したTNotebook用のTabのスタイル。
32
32
  - [Creating a New, Derived Style](https://tkdocs.com/tutorial/styles.html#styleoptions)

2

説明補足

2020/05/10 03:16

投稿

teamikl
teamikl

スコア8817

answer CHANGED
@@ -27,7 +27,8 @@
27
27
  - ttk.Label に style="TButton" のようなこともできます。(適切な用法かどうかはともかく)
28
28
  - スタイル名はリンク先にある表を参考に。大抵 "T" + クラス名ですが、例外有。(Treeview等)
29
29
  - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
30
- "TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。
30
+ ~~"TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。~~
31
+ 解釈としては、Tabから派生したTNotebook用のTabのスタイル。
31
32
  - [Creating a New, Derived Style](https://tkdocs.com/tutorial/styles.html#styleoptions)
32
33
  tcl/tkの大元の公式ドキュメントから紹介があるのはここ。
33
34
 

1

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

2020/05/10 03:15

投稿

teamikl
teamikl

スコア8817

answer CHANGED
@@ -17,4 +17,39 @@
17
17
  ```
18
18
  self.b = ttk.Button(self, text='Friday', style='Kim.TButton',
19
19
  command=self._fridayHandler)
20
+ ```
21
+
22
+
23
+ ----
24
+ 追記: スタイル名のルールについては、
25
+ 公式のドキュメントでも、あまり触れられていなかったと思います。
26
+
27
+ - ttk.Label に style="TButton" のようなこともできます。(適切な用法かどうかはともかく)
28
+ - スタイル名はリンク先にある表を参考に。大抵 "T" + クラス名ですが、例外有。(Treeview等)
29
+ - 上記のリンクには 'newName.oldName' と書かれていますが、これも反例有
30
+ "TNotebook.Tab" の様な、TNotebook の子要素の指定等もあり、ルールがとても曖昧です。
31
+ - [Creating a New, Derived Style](https://tkdocs.com/tutorial/styles.html#styleoptions)
32
+ tcl/tkの大元の公式ドキュメントから紹介があるのはここ。
33
+
34
+ > creating a new style (e.g. "Emergency.TButton") derived from the base style ("TButton") would be the appropriate thing to do.
35
+
36
+ 名前規則は、イメージとしては「継承」に近いです。
37
+ 例: AAA.TButton から更に派生した BBB.AAA.TButton を作成。
38
+
39
+ ```
40
+ import tkinter as tk
41
+ from tkinter import ttk
42
+
43
+ root = tk.Tk()
44
+ style = ttk.Style()
45
+
46
+ style.theme_use("clam") # TButton の背景色を簡単に変更する為
47
+ style.configure("AAA.TButton", background="black", foreground="white")
48
+ style.map("AAA.TButton", background=[("active","blue")])
49
+
50
+ # (AAA.TButton の backgroundを引継, foregroundを上書)
51
+ style.configure("BBB.AAA.TButton", foreground="yellow")
52
+
53
+ ttk.Button(root, text="HELLO", style="BBB.AAA.TButton").pack()
54
+ root.mainloop()
20
55
  ```