gpt4 book ai didi

text - Tcl/Tk : highlight some line in text widget or change the color for specific line text

转载 作者:行者123 更新时间:2023-12-01 09:55:03 27 4
gpt4 key购买 nike

我想为我的Tcl/Tk工具实现一个效果:在text控件中,根据具体情况,希望高亮一些线条的背景色,其他线条正常透明.有可能吗?
我尝试了一些选项,例如:-highlightbackground-insertbackground 等等,但没有人能做到这一点。
如果这不可能,如何更改特定行文本的颜色,这也是一种解决方法。

最佳答案

I hope to highlight some lines' background color, other lines are normal and transparent. It is possible?

是的。您可以通过在相关文本上设置一个标签 来实现。然后,您可以使用该标签配置文本,使其看起来像您想要的那样,其中可以包括更改字体、前景色和背景色。插入文本时或使用 tag add 设置标签方法。标签配置有 tag configure方法。

# Make a text widget and put some text in it
pack [text .t -height 10 -width 40]
.t insert 1.0 "This is an example of tagging."

# Set some tags; they have no style as yet
.t tag add foo 1.5 1.10
.t tag add bar 1.15 1.20

# Configure the tags so that we can see them
.t tag configure foo -font {Times 16 {bold italic}}
.t tag configure bar -foreground yellow -background blue

注意,选择实际上是一个特殊的标签,sel。您可以根据需要对其进行配置,但文本小部件的类绑定(bind)控制它的应用位置以响应用户操作。

关于text - Tcl/Tk : highlight some line in text widget or change the color for specific line text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911904/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com