0

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.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
Nirvan
  • 15
  • 7
  • Please try to look at tag descriptions before using them. The Mainframe relating to the tag has the same letters of the alphabet as your MainFrame, but there the similarity stops dead. I have edited to remove the tag. – Bill Woodger Jun 12 '15 at 12:56

1 Answers1

0

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" {}}
    }
}
Community
  • 1
  • 1
patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • Thank you, when I tried it alone, it's OK but I am working with OO tcl (oriented object), the internal function `_create_menubar` is not recognesid. the progam stops at `destroy .menubar` – Nirvan Jun 12 '15 at 12:56
  • when I tired only with `destroy .menubar` the menu is not destroyed ! – Nirvan Jun 12 '15 at 12:58
  • Yes yes, it works !! sorry, I have not used the correct toplevel, thank you very much – Nirvan Jun 12 '15 at 13:05
  • Hello, Is there any possibility to hide the menu instead of destroying it ? I am working with notebook, for each tab I have different menu. thank you – Nirvan Jun 15 '15 at 10:54
  • Not using the BWidget mainframe. This widget is designed to create a standard application window and expects to control the applications menubar. If you want to control sub-menus per tab then you should stop using BWidget and use a proper Tk menu. Then you can create the menu in code and attach or detach menu trees as you require. – patthoyts Jun 15 '15 at 12:13