Is it possible to have a tooltip with a popup menu in a toplevel window?
Here's the example in the manual which works:
package require tooltip
Demonstrate menu tooltip
. configure -menu [menu .menu]
.menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
.menu.test add command -label Tooltip
tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"
Here's my code (which doesn't work):
package require tooltip
toplevel .mytop
console show
set ::testcb 0
# Create a menu
label .mytop.label -text "Menu"
set m [menu .mytop.menu -tearoff 0 ]
$m add command -label "testcmd" -command "puts hello-testcmd"
$m add checkbutton -label "testcb" -variable ::testcb -indicatoron
1 -command {puts "$::testcb/checkbutton"}
pack .mytop.label
bind .mytop <1> {tk_popup .mytop.menu %X %Y}
tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0" >tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"
On Tue, 19 Dec 2023 16:10:00 -0800, et99 wrote:
Is it possible to have a tooltip with a popup menu in a toplevel window?**************************
Here's the example in the manual which works:
package require tooltip
Demonstrate menu tooltip
. configure -menu [menu .menu]
.menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
.menu.test add command -label Tooltip
tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"
Here's my code (which doesn't work):
package require tooltip
toplevel .mytop
console show
set ::testcb 0
# Create a menu
label .mytop.label -text "Menu"
set m [menu .mytop.menu -tearoff 0 ]
$m add command -label "testcmd" -command "puts hello-testcmd"
$m add checkbutton -label "testcb" -variable ::testcb -indicatoron >> 1 -command {puts "$::testcb/checkbutton"}
pack .mytop.label
bind .mytop <1> {tk_popup .mytop.menu %X %Y}
tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0"
tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"
I tried it in many ways and I could only make the tooltip appear by
removing the -index options, but then it appears whenever the menu is clicked, with no specific tooltips for each menu item like you very
probably meant.
I poked it a lot and it seems to me that tooltip is broken, or maybe
the manual is wrong.
greg schrieb am Mittwoch, 20. Dezember 2023 um 21:18:01 UTC+1:
et99 schrieb am Mittwoch, 20. Dezember 2023 um 08:22:57 UTC+1:
On 12/19/2023 5:58 PM, Luc wrote:Hello,
On Tue, 19 Dec 2023 16:10:00 -0800, et99 wrote:Thanks for looking into this. Yes, I want each menu item to have its own tooltip (or none).
Is it possible to have a tooltip with a popup menu in a toplevel window? >>>>>**************************
Here's the example in the manual which works:
package require tooltip
Demonstrate menu tooltip
. configure -menu [menu .menu]
.menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
.menu.test add command -label Tooltip
tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"
Here's my code (which doesn't work):
package require tooltip
toplevel .mytop
console show
set ::testcb 0
# Create a menu
label .mytop.label -text "Menu"
set m [menu .mytop.menu -tearoff 0 ]
$m add command -label "testcmd" -command "puts hello-testcmd"
$m add checkbutton -label "testcb" -variable ::testcb -indicatoron
1 -command {puts "$::testcb/checkbutton"}
pack .mytop.label
bind .mytop <1> {tk_popup .mytop.menu %X %Y}
tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0"
tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"
I tried it in many ways and I could only make the tooltip appear by
removing the -index options, but then it appears whenever the menu is
clicked, with no specific tooltips for each menu item like you very
probably meant.
I poked it a lot and it seems to me that tooltip is broken, or maybe
the manual is wrong.
Well, I have the tooltip code and first thing is,
for the code that works, there's a mirror copy of the .menu and .menu.test as:
w= |.#menu|
w= |.#menu.#menu#test|
And there's this:
# Menu events come from a funny path, map to the real path.
set m [string map {"#" "."} [winfo name $w]]
set cur [$w index active]
Although
% string map {"#" "."} .#menu.#menu#test
..menu..menu.test
So does Tk allow for multiple .. in a path, like with :::: in namespaces? >>>
But my menu's don't have those built by tooltip. So, from there, when it enters the code menuMotion, it doesn't seem to be what that code wants to see.
When moving the mouse into the menu's his has the above values for w, while mine are just
w= |.mytop.menu|
This is from adding some code at the top of
proc ::tooltip::menuMotion {w} {
variable G
puts "w= |$w| "
I added 2 more menu items in the working code (the first tearoff doesn't work):
. configure -menu [menu .menu -tearoff 1]
.menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
.menu.test add command -label Tooltip1
.menu.test add command -label Tooltip2
.menu.test add command -label Tooltip3
tooltip::tooltip .menu.test -index 0 "This is a menu tooltip0"
tooltip::tooltip .menu.test -index 1 "This is a menu tooltip1"
tooltip::tooltip .menu.test -index 2 "This is a menu tooltip2"
Here's what's he's storing, for his and mine
::::tooltip::tooltip(.menu.test,0) = This is a menu tooltip0
::::tooltip::tooltip(.menu.test,1) = This is a menu tooltip1
::::tooltip::tooltip(.menu.test,2) = This is a menu tooltip2
::::tooltip::tooltip(.mytop.menu,0) = this is a tooltip 0
::::tooltip::tooltip(.mytop.menu,testcb) = this is a tooltip 1
I'm thinking that you can't do this with another toplevel besides . or it's the configure -menu that's the problem, as I'm not using the menu bar.
with baltip
https://github.com/aplsimple/baltip
https://wiki.tcl-lang.org/page/baltip%2C+balloon+tip
#package require tooltip
package require baltip
toplevel .mytop
console show
set ::testcb 0
# Create a menu
label .mytop.label -text "Menu"
set m [menu .mytop.menu -tearoff 0 ]
$m add command -label "testcmd" -command "puts hello-testcmd"
$m add checkbutton -label "testcb" -variable ::testcb -indicatoron 1 -command {puts "$::testcb/checkbutton"}
pack .mytop.label
bind .mytop <1> {tk_popup .mytop.menu %X %Y}
::baltip::tip $m "this is tooltip 0" -index 0
::baltip::tip $m "this is tooltip 1" -index 1
a small change that is not necessary:
menu post instead of tk_popup
########
package require Tk
#package require tooltip
package require baltip
toplevel .mytop
#console show
set ::testcb 0
# Create a menu
label .mytop.label -text "Menu"
set m [menu .mytop.menu -tearoff 0 ]
$m add command -label "testcmd" -command "puts hello-testcmd"
$m add checkbutton -label "testcb" -variable ::testcb -indicatoron 1 -command {puts "$::testcb/checkbutton"}
pack .mytop.label
#menu post instead of tk_popup
#bind .mytop <1> {tk_popup .mytop.menu %X %Y}
bind .mytop <1> {.mytop.menu post %X %Y}
::baltip::tip $m "this is tooltip 0" -index 0
::baltip::tip $m "this is tooltip 1" -index 1
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 464 |
Nodes: | 16 (2 / 14) |
Uptime: | 161:16:38 |
Calls: | 9,385 |
Calls today: | 5 |
Files: | 13,561 |
Messages: | 6,096,399 |