TEXT widgetに出力する文字列を色分けして表示する方法について教えてください。
色分けの表示は以下のコードを実行した結果を期待しています。
import tkinter as tk from tkinter.scrolledtext import ScrolledText root = tk.Tk() txt = ScrolledText(root) txt.pack() txt.tag_config('warning', background="yellow", foreground="red") txt.tag_config('normal', background="white", foreground="black") txt.insert('end', "aaa\n", 'normal') txt.insert('end', "bbb\n", 'warning') txt.insert('end', "ccc\n", 'nomal') txt.insert('end', "ddd\n", 'nomal') root.mainloop()
実現したい事は、
以下のような list 形式の文字列から "bbb" の場合は 赤字で、その他は黒でTEXTへ表示させたいです。
listA = ['aaa','bbb','ccc','ddd']
いろいろ試してみたのですが結果がともないませんでした。
どなたかご教示いただけないでしょうか。
行いたいことがいまひとつ解りません。
上のコードと同じ処理になるように、 ListAをループで順番に insert していくだけでは駄目なのでしょうか。
回答1件
あなたの回答
tips
プレビュー