悬停在选项卡上时显示工具提示
Display tooltip when hovering on a tab
我正在使用 DynamicHelp 来显示工具提示。问题在于它仅在光标位于选项卡主体上时显示帮助:而不是当光标位于选项卡本身时。我想要发生的是当用户将鼠标悬停在选项卡上时显示帮助文本,而不是必须 select 选项卡,然后在显示帮助之前将光标移动到正文。
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]
}
}
}
虽然不是我想要的解决方案,但已经足够好了。为帮助文本创建标签,并将tab的入口绑定到标签
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 ""}
真的,你可以。您必须在命令 "insert"[=21= 中添加选项 -helptext ].
根据Bwidget doc:
[...]
pathName insert index page ?option value...?
Insert a new page identified by page at position index in the pages list. index must be numeric or end. The pathname of the new page
is returned. Dynamic help, if it is specified by the options, is
displayed when the pointer hovers over the tab that belongs to the
page.
-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.
[...]
我已经为笔记本小部件编写了一个小扩展,它完全符合您的要求。您可以从 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"
我正在使用 DynamicHelp 来显示工具提示。问题在于它仅在光标位于选项卡主体上时显示帮助:而不是当光标位于选项卡本身时。我想要发生的是当用户将鼠标悬停在选项卡上时显示帮助文本,而不是必须 select 选项卡,然后在显示帮助之前将光标移动到正文。
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]
}
}
}
虽然不是我想要的解决方案,但已经足够好了。为帮助文本创建标签,并将tab的入口绑定到标签
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 ""}
真的,你可以。您必须在命令 "insert"[=21= 中添加选项 -helptext ].
根据Bwidget doc:
[...]
pathName insert index page ?option value...?
Insert a new page identified by page at position index in the pages list. index must be numeric or end. The pathname of the new page is returned. Dynamic help, if it is specified by the options, is displayed when the pointer hovers over the tab that belongs to the page.
-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.
[...]
我已经为笔记本小部件编写了一个小扩展,它完全符合您的要求。您可以从 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"