简体   繁体   中英

How to make a StringVar with multiple colors in Tkinter?

Let's say we have a StringVar :

string_var = tk.StringVar(value="Red, Blue")
string_var.configure(fg='red')

Is it possible to configure this StringVar so that 'Red' will be colored red, and 'Blue' will be colored blue?

It is not possible. Instances of StringVar and the other tkinter variables don't have a visual representation.

The best option for text with multiple colors is to use a Text or Canvas widget. Both of those have the ability to add color to groups of text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM