試したこと
過去の掲載をヒントに 別々のスタイルを予め定義し これを各々のTREEVIEW配置時に 参照・適用されるようチャレンジしています。 以下コード内のstyle.configureの部分(★)です。
python
1 ############################################################################# 2 # # 3 # STYLE # 4 # # 5 ############################################################################# 6 style = ttk.Style() 7 style.theme_use('winnative') 8 style.configure("TButton", font=("Arial", 16)) 9 style.configure("TLabel", font=("Arial", 16), anchor='') 10 11 #style.configure("Treeview", background="black", foreground="white", fieldbackground="black", font=("Arial", 16), rowheight=25,) 12 #以下差替 ★★★別のツリービュで各々のデザインを適用したいため★★★ 13 style.configure("LTREE", background="black", foreground="white", fieldbackground="black", font=("Arial", 16), rowheight=25,) 14 style.configure("UTREE", background="white", foreground="black", fieldbackground="white", font=("Arial", 16), rowheight=25,) 15 16 style.configure("Treeview.Heading", background="green", foreground="white", font=("Arial", 16), rowheight=25,) 17 style.map("Treeview",background=[("selected", "silver")]) 18 style.map("Treeview",foreground=[("selected", "red")]) 19 ############################################################################# 20 # # 21 # 入出力定義メニュー用フレーム設置 # 22 # # 23 ############################################################################# 24 frmIOMenu = ttk.Frame(root, name="frmIOMenu") 25 frmIOMenu.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1) 26 frmIOMenu.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40) 27 frmIOMenu.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) 28 29 tree1 = ttk.Treeview(frmIOMenu, show="tree", style="LTREE") #★★★ 30 tree1.grid(row=3, column=0, rowspan=4, columnspan=5, sticky=tk.E + tk.W + tk.N + tk.S) 31 tree1.bind("<<StateSelect>>", partial(on_tree_state, True)) 32 tree1.bind("<<StateDeselect>>", partial(on_tree_state, False)) 33 tree1.bind("<<TreeviewSelect>>", on_tree_select)
困っていること
宣言したスタイルを適用できず それどころかエラーにもなってしまう
質問
個々のTREEVIEWに 別々の背景色・文字色を適用するには 如何したらよろしいのでしょうか?
現在の適用手続きでは 何が問題なのでしょうか?
初歩的なことかも知れませんが ご教示をお願いいたします。
17:43追記
ひょっとして、宣言名を 独自の文字列.Treeview にすれば ちゃんと適用できますかね?今から試します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。