/Why Tea
But certainly. Here's the example from man tk_popup, rewritten to use a
canvas:
# Create a menu
set m [menu .popupMenu]
$m add command -label "Example 1" -command bell
$m add command -label "Example 2" -command bell
# Create something to attach it to
pack [canvas .c]
# Arrange for the menu to pop up when the canvas is clicked
bind .c <1> {tk_popup .popupMenu %X %Y}
On Jan 25, 9:29 am, "suchenwi"
<richard.suchenwirth-bauersa...@siemens.com> wrote:
> On 25 Jan., 09:06, "Why Tea" <ytl...@gmail.com> wrote:
>
> > I'd like to run a small analog clock on a canvas, once it's clicked I'd
> > like to have a pop-up menu so that I can run other programs from there.
> > Can this be done with pure Tcl/Tk? (I knew about the menubutton, but I
> > don't think I can draw the analog clock on it)But certainly. Here's the example from man tk_popup, rewritten to use a
> canvas:
>
> # Create a menu
> set m [menu .popupMenu]
> $m add command -label "Example 1" -command bell
> $m add command -label "Example 2" -command bell
>
> # Create something to attach it to
> pack [canvas .c]
>
> # Arrange for the menu to pop up when the canvas is clicked
> bind .c <1> {tk_popup .popupMenu %X %Y}
It works. Thanks!
/Why Tea
Just for completeness: you could also bind to individual items on the
canvas instead of the canvas as a whole:
.c create ... -tags clock
.c bind clock <1> {tk_popup .popupMenu %X %Y}
See the canvas 'bind' subcommand for details:
http://www.tcl.tk/man/tcl8.4/TkCmd/canvas.htm#M38
R'
Others have posted how to do the popup.
For a precoded analog clock see http://wiki.tcl.tk/1011.
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
You are only limited by your imagination. You can either embed frames
within the canvas or use place to place them on top, or use tk_popup to
show genuine menus. Or, of course, you can create a new toplevel that
floats above everything else.
--
Bryan Oakley
www.tclscripting.com