Tcl Pinterest类型标记按钮

Tcl Pinterest类型标记按钮,tcl,Tcl,我想制作一些带有标签名称的动态按钮- 添加标签“name”应该有一个小按钮 在右边有一个十字来移除按钮-互动应该很像这个帖子中添加标签的方式 有人做过这样的事吗 这是针对TCL/TK 8.6的,类似这样: 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 [

我想制作一些带有标签名称的动态按钮-

添加标签“name”应该有一个小按钮 在右边有一个十字来移除按钮-互动应该很像这个帖子中添加标签的方式

有人做过这样的事吗

这是针对TCL/TK 8.6的,类似这样:

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
}
我的看法-

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]