Tkinter: populating Mac Help menu?

E

Edward K. Ream

Hello all,



Creating a 'Help' menu 'by hand' on the Mac does not work, or rather, it
creates a *second* Help menu.



There are hints about how to do this at:



http://tkinter.unpythonic.net/wiki/Widgets/Menu



but so far those hints have not been enough :) The following statements are
the result of several happy hours experimenting with dir(obj) for several
objects obj related to menus. (Jeeze, I love Python, but you knew that :)



The url above suggests that the 'official' Mac menu is named x.help, where x
is the Tk name (a string) of the menubar. If menubar is the Tkinter menubar
widget, then I assume that x = menubar._w.



So given x (a string), how does one create a widget whose name is '%s.help'
% x ? This is a can of corn in Tk, but nothing comes to mind looking at the
Tkinter source code.



If my app does *not* create a help menu, then even long after the Mac
menubar is created, and the official (empty) Help menu is visible,
menubar.children does *not* contain an entry for the official Mac Help menu.
Thus, there appears to be no way to populate the official Help menu after
letting Tkinter create the Help menu. Naturally, I could be wrong :)



Thanks for any help you can provide.


Edward
 
E

Eric Brunel

[snip]
So given x (a string), how does one create a widget whose name is
'%s.help'
% x ? This is a can of corn in Tk, but nothing comes to mind looking at
the
Tkinter source code.

Use the 'name' keyword when creating the menu itself:

----------------------------------------------------
from Tkinter import *

root = Tk()

mb = Menu(root)
root.configure(menu=mb)

## Normal menu
fm = Menu(mb)
fm.add_command(label='Quit', command=root.quit)
mb.add_cascade(label='File', menu=fm)

## Help menu with a specific name
hm = Menu(mb, name='help')
hm.add_command(label='About...')
mb.add_cascade(label='Help', menu=hm)

root.mainloop()
----------------------------------------------------

I didn't test it on MacOS-X, but the same trick should be used when
creating help menus on Unix (this menu is supposed to appear at the right
of the menubar according to Motif conventions).

HTH
 
E

Edward K. Ream

Thanks for these replies. I'll try these ideas soon and report back on my
experiences.

Edward
 
E

Edward K. Ream

hm = Menu(mb, name='help')

Yes, that worked. Many thanks for your help with Help.

Edward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top