【问题标题】:Pinterest type tagged buttonsPinterest 类型标记按钮
【发布时间】:2019-03-25 10:19:19
【问题描述】:

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

add_tag "name" 应该做一个小按钮 右侧的十字删除按钮 - 交互应该类似于此帖子中添加标签的方式

有人做过这样的事情吗?

这是 TCL/TK 8.6

【问题讨论】:

    标签: tcl


    【解决方案1】:

    类似这样的:

    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
    }
    

    【讨论】:

      【解决方案2】:

      我的看法-

      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]
      

      【讨论】:

        猜你喜欢
        • 2012-03-26
        • 1970-01-01
        • 1970-01-01
        • 2013-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-14
        • 2013-10-15
        相关资源
        最近更新 更多