代码之家  ›  专栏  ›  技术社区  ›  cup

在选项卡上悬停时显示工具提示

  •  2
  • cup  · 技术社区  · 6 年前

    我正在使用DynamicHelp显示工具提示。问题是,它只在光标位于选项卡主体上时显示帮助:而不是在光标位于选项卡本身上时显示帮助。我希望在用户将鼠标悬停在选项卡上时显示帮助文本,而不必选择选项卡,然后在显示帮助之前将光标移到正文中。

    package require BWidget
    
     ## create a notebook with 2 text panes
     NoteBook .n
     .n insert 0 tb1 -text "Tab 1"
     .n insert 1 tb2 -text "Tab 2"
     foreach panel {tb1 tb2} {
        set pane [.n getframe $panel]
        text $pane.t
        pack $pane.t -fill both -expand 1
     }
     pack .n
     .n raise tb1
    
    #                    ,-- How do I get the tab?
    DynamicHelp::add [.n getframe tb1] -text "The essence of silly\nsally silica"
    DynamicHelp::add [.n getframe tb2] -text "acetyl sali cylic\nacid is aspirin"
    

    我在笔记本实现中发现了这段代码-我不知道它是否有用。我搞不懂它是怎么从这里得到标签的。

    proc NoteBook::_highlight { type path page } {
        variable $path
        upvar 0  $path data
    
        if { [string equal [Widget::cget $path.f$page -state] "disabled"] } {
            return
        }
    
        switch -- $type {
            on {
                $path.c itemconfigure "$page:poly" \
                -fill [_getoption $path $page -activebackground]
                $path.c itemconfigure "$page:text" \
                -fill [_getoption $path $page -activeforeground]
            }
            off {
                $path.c itemconfigure "$page:poly" \
                -fill [_getoption $path $page -background]
                $path.c itemconfigure "$page:text" \
                -fill [_getoption $path $page -foreground]
            }
        }
    }
    
    3 回复  |  直到 6 年前
        1
  •  0
  •   L. Alejandro M.    6 年前

    真的,你可以。必须添加选项 -帮助文本 “插入” .

    根据 Bwidget doc

    [...]

    路径名插入索引页?选项值。。。?

    在“页面”列表中的位置索引处插入由“页面”标识的新页面。索引必须是数字或结尾。新页的路径名 已返回。动态帮助(如果由选项指定)是

    -helpcmd
        Has no effect. See also DynamicHelp. 
    
    -helptext
        Text for dynamic help. If empty, no help is available for this page. See also DynamicHelp. 
    
    -helptype
        Type of dynamic help. Use balloon (the default for a NoteBook page) or variable. See also DynamicHelp. 
    
    -helpvar
        Variable to use when -helptype option is variable. See also DynamicHelp. 
    

    [...]

        2
  •  1
  •   HanT    6 年前

    我已经为Notebook小部件编写了一个小扩展,它完全满足您的需求。你可以从 notebook-tip.tcl . 使用方法如下:

    package require BWidget
    source notebook-tip.tcl
    
    NoteBook .n
    .n insert 0 tb1 -text "Tab 1"
    .n balloon tb1 "balloon text for Tab 1"
    .n insert 1 tb2 -text "Tab 2"
    .n balloon tb2 "balloon text for Tab 2"
    foreach panel {tb1 tb2} {
      # add contents
      set pane [.n getframe $panel]
      text $pane.t
      pack $pane.t -fill both -expand 1
    }
    .n raise tb1
    grid .n -sticky ew
    

    可以使用itemconfigure动态更改引出序号文本:

    $path itemconfigure $page -balloon text
    

    例如:

    .n itemconfigure tb1 -balloon "another text"
    
        3
  •  0
  •   cup    6 年前

    不是我想要的解决方案,但已经足够好了。为帮助文本创建标签,并将选项卡的条目绑定到标签

    package require BWidget
    
    # Creat a bar for help
    grid [label .l1 -textvariable tabhelp -justify left] -sticky w -row 0
    ## create a notebook with 2 text panes
    NoteBook .n
    .n insert 0 tb1 -text "Tab 1"
    .n insert 1 tb2 -text "Tab 2"
    foreach panel {tb1 tb2} {
       set pane [.n getframe $panel]
       text $pane.t
       pack $pane.t -fill both -expand 1
    }
    .n raise tb1
    grid .n -sticky ew -row 1
    
    DynamicHelp::add [.n getframe tb1] -text "The essence of silly\nsally silica"
    DynamicHelp::add [.n getframe tb2] -text "acetyl sali cylic\nacid is aspirin"
    
    # Add help on entry into the tabs
    .n.c bind p:tb1 <Enter> {set tabhelp "Woody Woodpecker"}
    .n.c bind p:tb1 <Leave> {set tabhelp ""}
    
    .n.c bind p:tb2 <Enter> {set tabhelp "Aspirins are great"}
    .n.c bind p:tb2 <Leave> {set tabhelp ""}