updating Menu MainFrame tk

109 views Asked by At

I am looking how I can update the menu of my application. I used MainFrame to create it but I can't update the whole menu.

set descmenu1 {}

set FileMenuItems1 {}
lappend FileMenuItems1   [list command "f1"  {} "f1" {Ctrl q} -command [list if {[tk_messageBox -message [format "%s ?" "Quit"] -type yesno] eq "yes"} {exit}]]
lappend descmenu1 "&file" all file 0 $FileMenuItems1

set EditMenu {}
lappend EditMenu1   [list command "e1"  {} "e1" {Ctrl q} -command [list if {[tk_messageBox -message [format "%s ?" "Quit"] -type yesno] eq "yes"} {exit}]]
lappend descmenu1 "&Edition" all file 0 $EditMenu1

set descmenu2 {}
set FileMenuItems2 {}
lappend FileMenuItems2   [list command "f2"  {} "f2" {Ctrl q} -command [list if {[tk_messageBox -message [format "%s ?" "Quit"] -type yesno] eq "yes"} {exit}]]
lappend descmenu2 "&file2" all file 0 $FileMenuItems2

set EditMenu2 {}
lappend EditMenu2   [list command "e2"  {} "e2" {Ctrl q} -command [list if {[tk_messageBox -message [format "%s ?" "Quit"] -type yesno] eq "yes"} {exit}]]
lappend descmenu2 "&Edition2" all file 0 $EditMenu2


set mainframe [MainFrame .hull -menu $descmenu1]
.hull configure -menu $descmenu2

How I can update my menu using MainFrame? Actually, the menu displayed is descmenu1.

1

There are 1 answers

5
patthoyts On BEST ANSWER

You have not specified this but it looks like you are using BWidget. The -menu option on the BWidget MainFrame takes a list that describes a menu hierarchy rather than a menu widget. However, the -configure option does not redefine the menu.

It seems you can force it to redefine the menu by destroying the existing one and using the internal _create_menubar procedure to parse a new menu list. However, maybe you should consider doing this some other way if you have to start using internal methods. A normal Tk toplevel exposes the menu widget tree for you to manipulate as desired. Possibly a BWidget MainFrame is not really helping you here.

Demo

package require BWidget
set main [MainFrame .main -menu {
    "&File" {} {} 0 {
        {command "&New" {} "Create new" {}}
        {separator}
        {command "E&xit" {} "Exit app" {}}
    }
}]
destroy .menubar
$main _create_menubar {
    "&Different" {} {} 0 {
        {command "Alternate" {} "Something new" {}}
    }
}