简体   繁体   English

如何在 Tkinter 中制作具有多个 colors 的 StringVar?

[英]How to make a StringVar with multiple colors in Tkinter?

Let's say we have a StringVar :假设我们有一个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?是否可以配置此 StringVar 以使“Red”变为红色,而“Blue”变为蓝色?

It is not possible.这不可能。 Instances of StringVar and the other tkinter variables don't have a visual representation. StringVar和其他 tkinter 变量的实例没有可视化表示。

The best option for text with multiple colors is to use a Text or Canvas widget.具有多个 colors 的文本的最佳选择是使用TextCanvas小部件。 Both of those have the ability to add color to groups of text.两者都能够为文本组添加颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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