[Tkinter-discuss] a couple of mac menu problems
Kevin Walzer
kw at codebykevin.com
Fri Jun 15 20:32:47 CEST 2012
What version of OS X?
Sent from my iPhone
On Jun 15, 2012, at 2:06 PM, Lynn Oliver <raycores at gmail.com> wrote:
> Along the same lines, I managed to get application/preferences to work on the Mac, but while application/about shows the name of my Python app (built with pyinstaller), it displays the 'Tcl & Tk' dialog.
>
> The TkDocs-TK Tutorial on menus shows this as a TODO item (http://www.tkdocs.com/tutorial/menus.html). While I was able to figure out the preferences menu by looking at the idlelib sources, I couldn't get the application/about menu to work.
>
> Any suggestions?
>
> Lynn
> On Jun 15, 2012, at 6:45 AM, Kevin Walzer wrote:
>
>> Hi Mark,
>>
>> Please see my answers below:
>>
>>
>>> Here's a bit of code used to create the Help menu:
>>>
>>> if MAC:
>>> self.master.createcommand("tkAboutDialog", self.about_action)
>>> self.master.createcommand("::tk::mac::ShowHelp",
>>> self.help_action)
>>> helpMenu = tk.Menu(self.menubar, name="help")
>>> helpMenu.add_command(label="Help", underline=0,
>>> command=self.help_action)
>>> if not MAC:
>>> helpMenu.add_command(label="About", underline=0,
>>> command=self.about_action)
>>> self.menubar.add_cascade(label="Help", underline=0,
>>> menu=helpMenu)
>>
>> There's some magic in the Tk-Cocoa help menu--if you define the tk::mac::showHelp command and map it to your function that calls user help, you don't need to add a separate entry for help. (There's already an entry hard-coded for help, along with the search field.) So the helpMenu.add_Command(label="Help")... stuff is redundant.
>>
>>> I end up with these menus:
>>>
>>> ActivePython3.2
>>> About ActivePython3.2 # correctly invokes my about action
>>
>> If you're just running the app from Python and not wrapping it with a tool such as py2app, this is the expected behavior. The "about" menu picks up the name of the executable from its info.plist file, which in this case is Python.
>>
>>>
>>> Help
>>> Search # some apple-specific thing that just appears
>>> ActivePython3.2 Help # invokes my help action
>>> Help # invokes my help action
>>
>>>
>>> Problems:
>>>
>>> (1) I don't know how to rename the "ActivePython3.2" menu to "My App".
>>> (2) I don't know how to rename the "About ActivePython3.2" menu option
>>> to "About" or "About My App".
>>
>> See above--you need to wrap this as a standalone app using py2app or cx_freeze.
>>
>>> (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option.
>>> If I don't do helpMenu.add_command() on the Mac that menu has no
>>> items ('cos the About is in the ActivePython3.2 menu) and so the
>>> Help menu doesn't appear at all.
>>
>> If you don't add any items to the help menu but just define it, I would expect to see an entry called "ActivePython 3.2 Help" that calls up a dialog which says, "Help isn't available for ActivePython 3.2."
>>
>> This is how I set up my help menu is one of my Python apps:
>>
>> self.createcommand('::tk::mac::ShowHelp', self.runHelp)
>>
>> self.helpmenu = Menu(self.mb, name='_help')
>> self.mb.add_cascade(label='Help', menu=self.helpmenu)
>> self.helpmenu.add_command(label='Phynchronicity Help', command=self.runHelp)
>> self.helpmenu.add_command(label='Contact Code by Kevin', command=self.getHelp)
>> self.helpmenu.add_command(label='Web Site', command=self.getWebSite)
>> self.helpmenu.add_command(label='User Forum', command=self.getUserForum)
>> self.helpmenu.add_command(label='Newsletter', command=self.getNewsletter)
>>
>> Hope this helps,
>> Kevin
>>
>> --
>> Kevin Walzer
>> Code by Kevin
>> http://www.codebykevin.com
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
More information about the Tkinter-discuss
mailing list