6

I have a simple Tcl script that creates a window with a menu.

#! /usr/bin/tclsh
package require Tk
#  Create the main message window
message .m -text {Hello Tcl!} -background white
pack .m -expand true -fill both -ipadx 100 -ipady 40

#  Create the main menu bar with a Help-About entry
menu .menubar
menu .menubar.help -tearoff 0
.menubar add cascade -label Help -menu .menubar.help -underline 0
.menubar.help add command -label {About Hello ...} \
    -accelerator F1 -underline 0 -command showAbout

#  Define a procedure - an action for Help-About
proc showAbout {} {
    tk_messageBox -message "Tcl/Tk\nHello Windows\nVersion 1.0" \
        -title {About Hello}
}

#  Configure the main window 
wm title . {Hello Foundation Application}
. configure -menu .menubar -width 200 -height 150
bind . {<Key F1>} {showAbout}

If this script is run on Ubuntu using the Unity window manager the menu is placed on the window and not on the top-most bar (similiar to MacOSX) where other native programs put their menus. Like this:

enter image description here

Is this a limitation on Tcl/Tk or is there a way to make the menu behave more natively under Unity and be placed at the top of the screen not on the window?

Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199
  • Thanks for the pic! Now I see what your problem is (it's really the first time I see a global menubar). You could perhaps try something with `post`. When I do `.menu post 0 0` that makes (a clone of) the menu appear at the top left. This has a global grab though and disappears when it loses focus. So, I believe a global menu should be doable/customized if required. – Jerry Mar 27 '14 at 17:55
  • It's not just a clone of the menu i want. I want it to appear as all the other program's menus do, at the top left of the screen, just like Mac OSX. – Gary Willoughby Mar 27 '14 at 19:56
  • Excellent question. I've no idea how to do it, to be honest! – Donal Fellows Mar 27 '14 at 22:54
  • The toplevel is controlled by the window manage. Try the wm -type attribute found in 8.59 and greater? Don't have that version to test it. – don_q Jul 18 '14 at 21:46

1 Answers1

0

I think you need to try using the Gnocl package. Standard Tk doesn't implement application level menus. The Tk menus have to be attached to the window.

David B
  • 71
  • 3