아래의 커맨드로 위젯이 툴팁을 달 수 있습니다.
proc setTooltip {widget text} {
if { $text != "" } {
bind $widget <Any-Enter> [list after 500 [list showTooltip %W $text]]
bind $widget <Any-Leave> [list after 500 [list destroy %W.tooltip]]
bind $widget <Any-KeyPress> [list after 500 [list destroy %W.tooltip]]
bind $widget <Any-Button> [list after 500 [list destroy %W.tooltip]]
}
}
proc showTooltip {widget text} {
global tcl_platform
if { [string match $widget* [winfo containing \
[winfo pointerx .] [winfo pointery .]] ] == 0 } {
return
}
catch { destroy $widget.tooltip }
set scrh [winfo screenheight $widget] ; # 1) flashing window fix
set scrw [winfo screenwidth $widget] ; # 1) flashing window fix
set tooltip [toplevel $widget.tooltip -bd 1 -bg black]
wm geometry $tooltip +$scrh+$scrw ; # 1) flashing window fix
wm overrideredirect $tooltip 1
if {$tcl_platform(platform) == {windows}} { ; # 3) wm attributes...
wm attributes $tooltip -alpha 0.9
wm attributes $tooltip -topmost 1 ; # 3) assumes...
} ; # 3) Windows
pack [label $tooltip.label -bg lightyellow -fg black -text $text -justify left]
set width [winfo reqwidth $tooltip.label]
set height [winfo reqheight $tooltip.label]
set positionX [winfo pointerx .]
set positionY [expr [winfo pointery .] + 5]
wm geometry $tooltip [join "$width x $height + $positionX + $positionY" {}]
raise $tooltip
# 2) Kludge: defeat rare artifact by passing mouse over a tooltip to destroy it.
bind $widget.tooltip <Any-Enter> {destroy %W}
bind $widget.tooltip <Any-Leave> {destroy %W}
}
pack [button .b -text hello]
setTooltip .b "Hello World!"
'Tcl & Tk > 팁 (Tip)' 카테고리의 다른 글
필요시만 스크롤바 보이게 하기 (0) | 2025.03.06 |
---|---|
Wish8x를 실행시킬 때 마다 특정 코드를 자동실행 (0) | 2025.03.06 |
특정 윈도우의 자식 윗젯들을 한꺼번에 없애기 (0) | 2025.03.06 |
음악에 쓰이는 음들의 진동수(주파수) 구하는 식 (0) | 2025.03.06 |
문자열로 비트맵 이미지 만들기 (0) | 2025.03.06 |