Enhancement suggestion regarding menus 
Author Message
 Enhancement suggestion regarding menus

        Now that I have written a complete gui with Tcl/Tk for a database
application, I wanted to post a couple of suggestions in regards to

1) Keeping track of tearoff menu window names so only one instance of a
tearoff menu is created (if it already exists then raise it).

2) If the menu window name was stored then the user could access it to
set the size of the window.  As it is now, the tearoff menu windows name
is generated at random so the user is unable to set the size etc. which
in some cases results in a tearoff window with a titlebar that is too

Granted neither of these items are show stoppers but it would make this
portion of a GUI a little slicker.  Below is some of the code I have
used to implement this (added to tearoff.tcl):

    global ActiveTearOffMenus

    # If the menu exists then check to see if the window exists - if the
    # window was destroyed due to the parent being destroyed then the
    # array will not have been updated.

    set BuildTearOff 1

    if { [info exists ActiveTearOffMenus($w)] } {
        set WinName $ActiveTearOffMenus($w)
        if { [winfo exists $WinName] } {
            raise $WinName
            set BuildTearOff 0
        } else {
            # remove menu index form the tear off menu array
            unset ActiveTearOffMenus($w)

    if { $BuildTearOff == 1 } {
        # follow with existing tkTearOffMenu code
        .       # update the active tear off menu array
        set ActiveTearOffMenus($w) $menu

        # Modify switch so we can determine title length later
        switch [winfo class $parent] {
            Menubutton {
                set TitleString [$parent cget -text]
            Menu {
                set TitleString [$parent entrycget active -label]
        wm title $menu $TitleString

        # set title length - 15 used for testing would need text metrics
        # to determine proper spacing
        set TitleLength [expr [string length $TitleString] * 15]
        wm minsize $menu $TitleLength 10

        # Have menu call specific routine when destroyed
        wm protocol $menu WM_DELETE_WINDOW "DestroyTearOff $w"

proc DestroyTearOff { menu } {
    global ActiveTearOffMenus

    # If top level still exists
    # then destroy it
    if { [winfo exists $ActiveTearOffMenus($menu)] } {
        destroy $ActiveTearOffMenus($menu)

    # Remove menu index from the tear off menu array
    unset ActiveTearOffMenus($menu)


Dan Milligan

Sun, 09 May 1999 03:00:00 GMT  
 Enhancement suggestion regarding menus

>    Now that I have written a complete gui with Tcl/Tk for a database
>application, I wanted to post a couple of suggestions in regards to menus.

The menu system is being overhauled in a future version of Tk.  This
includes better control over tearoffs.

     Jeffrey Hobbs                       office: 541.683.7891

              URL: http://www.cs.uoregon.edu/~jhobbs/

Wed, 12 May 1999 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Enhancement suggestion (half-baked)

2. Simple View Composer Enhancement Suggestions

3. CW20: Enhancement \ Fixes : Suggestions

4. Inviting feature enhancement suggestions for gnuplotfortran

5. Whats about following enhancement suggestion?

6. Suggestion for Enhancement to Tcl

7. Minor suggestion regarding if/unless conditionals

8. Minor suggestion regarding if/unless conditionals

9. a heretical suggestion regarding Pop's lexical rules

10. CW 2.0 question regarding Menus?

11. A menu suggestion

12. Need suggestions for menu system


Powered by phpBB® Forum Software