Tcl ttk::标签多行格式
我想这样显示我的行:Tcl ttk::标签多行格式,tcl,tk,Tcl,Tk,我想这样显示我的行: Nombre de seq(s) = 10 Nombre de page(s) = 12 Fichier word = c:/temp/word.docx Fichier simulation = c:/temp/word.tmp 但在我的标签中,我的线条显示如下 我怎样才能使我的线条与等号对齐 下面是我的代码: package require Tk lappend info [format "%-20s = %-1s" "Nombr
Nombre de seq(s) = 10
Nombre de page(s) = 12
Fichier word = c:/temp/word.docx
Fichier simulation = c:/temp/word.tmp
但在我的标签中,我的线条显示如下
我怎样才能使我的线条与等号对齐
下面是我的代码:
package require Tk
lappend info [format "%-20s = %-1s" "Nombre de seq(s)" 10]
lappend info [format "%-20s = %-1s" "Nombre de page(s)" 1]
lappend info [format "%-20s = %-1s" "Fichier word" {c:/temp/word.docx}]
lappend info [format "%-20s = %-1s" "Fichier simulation" {c:/temp/word.tmp}]
grid [ttk::label .l -text [join $info "\n"]] -row 0 -column 0 -padx 2 -pady 2 -sticky nw
最简单的方法是将标签配置为使用固定字体 如果你想要一个比例字体,那么你可以把东西分成8个单独的标签,并把它们放在一个网格中 要使用比例字体且仅使用一个标签,您可以使用unicode中可用的不同空格:
set data {
"Nombre de seq(s)" 10
"Nombre de page(s)" 12
"Fichier word" "c:/temp/word.docx"
"Fichier simulation" "c:/temp/word.tmp"
}
# Put the different size spaces in a dict
set spaces [dict create [font measure TkDefaultFont " "] " "]
for {set i 0x2000} {$i <= 0x200a} {incr i} {
set s [format %c $i]
dict set spaces [font measure TkDefaultFont $s] $s
}
# A 0-width space could cause an endless loop
dict unset spaces 0
# Sort the dict to be able to use a bisect lsearch
set spaces [lsort -integer -index 0 -stride 2 $spaces]
# Calculate the sizes of the lefthand terms and find the longest
set sizes [lmap n [dict keys $data] {font measure TkDefaultFont $n}]
set max [tcl::mathfunc::max {*}$sizes]
set txt [lmap s [dict keys $data] l $sizes {
set v [dict get $data $s]
# Keep adding the biggest space that will fit
# until the string is the same length as the longest one
while {$l < $max} {
set w [expr {$max - $l}]
set key [lsearch -inline -integer -bisect [dict keys $spaces] $w]
append s [dict get $spaces $key]
incr l $key
}
# Append the value
append s " = " $v
}]
# Combine the lines and show them on a label
ttk::label .l -text [join $txt \n]
grid .l
设置数据{
“序号编号”10
“页码编号”12
Fichier word“c:/temp/word.docx”
Fichier模拟“c:/temp/word.tmp”
}
#把不同大小的空格放在一张纸上
设置空格[dict create[font measure TkDefaultFont”“]]
对于{set i 0x2000}{$i最简单的方法是将标签配置为使用固定字体
如果你想要一个比例字体,那么你可以把东西分成8个单独的标签,并把它们放在一个网格中
要使用比例字体且仅使用一个标签,您可以使用unicode中可用的不同空格:
set data {
"Nombre de seq(s)" 10
"Nombre de page(s)" 12
"Fichier word" "c:/temp/word.docx"
"Fichier simulation" "c:/temp/word.tmp"
}
# Put the different size spaces in a dict
set spaces [dict create [font measure TkDefaultFont " "] " "]
for {set i 0x2000} {$i <= 0x200a} {incr i} {
set s [format %c $i]
dict set spaces [font measure TkDefaultFont $s] $s
}
# A 0-width space could cause an endless loop
dict unset spaces 0
# Sort the dict to be able to use a bisect lsearch
set spaces [lsort -integer -index 0 -stride 2 $spaces]
# Calculate the sizes of the lefthand terms and find the longest
set sizes [lmap n [dict keys $data] {font measure TkDefaultFont $n}]
set max [tcl::mathfunc::max {*}$sizes]
set txt [lmap s [dict keys $data] l $sizes {
set v [dict get $data $s]
# Keep adding the biggest space that will fit
# until the string is the same length as the longest one
while {$l < $max} {
set w [expr {$max - $l}]
set key [lsearch -inline -integer -bisect [dict keys $spaces] $w]
append s [dict get $spaces $key]
incr l $key
}
# Append the value
append s " = " $v
}]
# Combine the lines and show them on a label
ttk::label .l -text [join $txt \n]
grid .l
设置数据{
“序号编号”10
“页码编号”12
Fichier word“c:/temp/word.docx”
Fichier模拟“c:/temp/word.tmp”
}
#把不同大小的空格放在一张纸上
设置空格[dict create[font measure TkDefaultFont”“]]
对于{set i 0x2000}{$i标签小部件并不是专门为这类事情设计的。您可以使用固定宽度字体,也可以尝试插入选项卡:
pack [ttk::label .l -textvariable foo]
# Doing this directly rather than computing it
set foo "Nombre de seq(s)\t\t= 10
Nombre de page(s)\t= 12
Fichier word\t\t= c:/temp/word.docx
Fichier simulation\t\t= c:/temp/word.tmp"
制表符在这里有点棘手,因为行长度之间的差异太大,它们无法自动隐藏
不过,最好的选择可能是使用只读文本小部件,因为该小部件可以让您精确控制布局
pack [text .t -font TkDefaultFont]
.t insert 1.0 "Nombre de seq(s)\t= 10
Nombre de page(s)\t= 12
Fichier word\t= c:/temp/word.docx
Fichier simulation\t= c:/temp/word.tmp"
.t configure -tabs [font measure TkDefaultFont "Nombre de page(s) "] -state disabled
# You MUST insert the text before disabling the widget.
(您需要试验如何获得正确的整体小部件宽度。以及设置背景的颜色。)标签小部件并不是专门为这类事情设计的。您可以使用固定宽度字体,也可以尝试插入选项卡:
pack [ttk::label .l -textvariable foo]
# Doing this directly rather than computing it
set foo "Nombre de seq(s)\t\t= 10
Nombre de page(s)\t= 12
Fichier word\t\t= c:/temp/word.docx
Fichier simulation\t\t= c:/temp/word.tmp"
制表符在这里有点棘手,因为行长度之间的差异太大,它们无法自动隐藏
不过,最好的选择可能是使用只读文本小部件,因为该小部件可以让您精确控制布局
pack [text .t -font TkDefaultFont]
.t insert 1.0 "Nombre de seq(s)\t= 10
Nombre de page(s)\t= 12
Fichier word\t= c:/temp/word.docx
Fichier simulation\t= c:/temp/word.tmp"
.t configure -tabs [font measure TkDefaultFont "Nombre de page(s) "] -state disabled
# You MUST insert the text before disabling the widget.
(您需要试验如何正确设置小部件的整体宽度,以及背景的颜色。)