Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pop-up menu from canvas?

103 views
Skip to first unread message

Why Tea

unread,
Jan 25, 2007, 3:06:27 AM1/25/07
to
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)

/Why Tea

suchenwi

unread,
Jan 25, 2007, 3:29:34 AM1/25/07
to

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}

Why Tea

unread,
Jan 25, 2007, 4:28:55 AM1/25/07
to

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

Ralf Fassel

unread,
Jan 25, 2007, 8:14:05 AM1/25/07
to
* "Why Tea" <ytl...@gmail.com>

| > # 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!

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'

Gerald W. Lester

unread,
Jan 25, 2007, 9:36:10 AM1/25/07
to

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|
+------------------------------------------------------------------------+

Bryan Oakley

unread,
Jan 31, 2007, 4:32:50 PM1/31/07
to

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

0 new messages