<menu-button> re-text/labling

From: Ben L. Di Vito <b.l.divito_at_larc.nasa.gov>
Date: Fri, 6 Oct 2000 13:48:21 -0400 (EDT)

Paul.Emsley_at_chem.gla.ac.uk writes:
> Hello,
> Consider the following:
> (require "Tk-classes")
> (define mb (make <Menu-Button>
> :text "none"
> :relief "raised"
> :indicator-on #t))
> (define mb-menu (make <Menu> :parent mb))
> (pack mb :padx 4 :pady 4)
> (map (lambda (x)
> (menu-add mb-menu 'command
> :label x
> :command (lambda() (format #t "~s~%" x))))
> (list "one" "two" "three"))
> All very fine so far.
> Now, I want the menu-button to change to the appropriate button
> label when I select that label (i.e. selecting "one" turns
> "none" to "one").
> How do I do that?

There are several ways. Here's one that uses an STklos slot update:

(map (lambda (x)
       (menu-add mb-menu 'command
                 :label x
                 :command (lambda () (slot-set! mb 'text x))))
     (list "one" "two" "three"))

You could also operate at a lower level and manipulate the Tk widget
configuration via:

    ((id mb) 'config :text "one")

> How should I have found this out on my own?

The STk manual should have most of what you need. There's also a
paper that comes with the distribution on using STklos to access Tk

If you need background on Tk itself, there's plenty available at the
Tcl/Tk web sites. There also are several books out there. I like the
book by Brent Welch (sorry, I don't have a reference with me now).

Ben Di Vito
Received on Fri Oct 06 2000 - 19:21:53 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST