[有人曾经做过或不知道如何进行自动[label
]换行吗?还是自我智能地认识到到达每行末尾(即,在边缘的边缘)的信息,仅限于小部件本身?
package require Img
# Container
frame .fr -borderwidth 2 -bg white
# Text Variable
set description "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris"
# Thumbnail
image create photo pic -file /home/tc/webvideo/galinha_pitadinha/seu_lobato.jpg
button .fr.bt -relief flat -bg white -image pic
# Description
label .fr.lb -bg white -textvariable description -wraplength 250 -width 30 -justify left
pack .fr .fr.bt .fr.lb -side left -fill x -padx .5c -pady .5c
从编程上来说,我希望它看起来像这样:
我想打破句子,以及上面的说明性图像。
请注意,缺少正则表达式来寻找第二行的结尾,并在结尾处嫁接小花盆(椭圆)。当然,隐藏其余文本。
通过以下方式将所有文字悬停在label
小部件上:tooltip
我一直在思考两个假设。他们是:
1)显示“文本”变量中“字符”的总数
tk_messageBox -message [string length $description]
2)显示文本变量内“单词”的总数
tk_messageBox -message [llength $description]
在
-wraplength 250
属性的此设置中,我每两行就有10个字的变体。基于此,我可以应用一个条件,并将word或character的数量作为确定因素,使其仅显示到第二行。
# If it were to quantify Characters and not words, this would be
if {[string length $description] < 40} {
pack [label .b -textvariable description -wraplength 250 -width 30 -justify left] -side top -fill x
}
或比较一定数量的单词,在这种情况下为10个单词。如果为true,请执行正则表达式的操作
# If it were to quantify words and not characters, this would be
if {[llength $description] <10} {
... RegExp code here ...
}
label小部件使用-wraplength
option。要采用任何形式的屏幕距离度量值(例如-wraplength
为190像素,190
为5厘米),都需要套用包装宽度。
(很少使用的)message小部件可以专注于尝试为其包含的文本获得特定的长宽比。