我想制作一些带有标签名称的动态按钮-
add_tag“名称”应该用一个小按钮 右侧有一个十字形以删除按钮-交互应该类似于在此帖子中添加标签的方式
有人做了这样的事情吗?
这是针对TCL / TK 8.6
答案 0 :(得分:0)
类似这样的东西:
proc add_tag_close_btn {t} {
# button inside tag widget without border with red x :
set b ${t}.x
button $b -text "x" -bd 0 -fg red -command [list destroy $t]
# place it at top/right corner, 8x8 size:
place $b -anchor ne -rely 0 -relx 1 -height 8 -width 8
}
# test:
foreach i {1 2 3 4 5} {
set t .tag$i
button $t -text "Tag Btn $i" -command "..."
grid $t -column $i -row 1
$t configure -width 10
add_tag_close_btn $t
}
答案 1 :(得分:0)
我的评价-
catch {font delete MySmallFont}
font create MySmallFont {*}[font configure TkDefaultFont] -size 6
proc make_tag_window {w text {color yellow}} {
# Pad with spaces to leave a little gap
label $w -text "$text " -background $color
# Placement cosmetics easier with a smaller font and no padding
set closew [button $w.b -text X -font MySmallFont -background $color -relief flat -pady 0 -borderwidth 0 -command [list destroy $w]]
# Place X in top left corner. We do not use -width -height because they can truncate
place $closew -in $w -relx 1 -anchor ne -bordermode outside
raise $closew
return $w
}
#demo
grid [make_tag_window .t1 "Tag A"] [make_tag_window .t2 "Tag B" red]