Hi Kevin,

I initially do:

        if sys.platform == "darwin": CmdKey="Command-"
        else: CmdKey="Control-"

...and then I define menu items as:

        myMenu.add_command(label="Quit", command=self.mainWin.Quit,
accelerator=CmdKey+'Q')

Mick

On 26 December 2015 at 03:19, Kevin Walzer <k...@codebykevin.com> wrote:
> I'm porting a Tkinter application from Mac to Windows and I need a
> cross-platform way to implement accelerator keys for menu entries. In Tcl,
> this is very simple:
>
>  -accelerator "$Command-C"
>
> where $Command can be set to "Command" or "Control" depending on the
> platform.
>
> Python does not have as flexible a string substitution as Tcl, so I'm
> looking for a Pythonic way to do this. Most examples I've seen load entirely
> separate menus depending on the platform, and I'd rather avoid duplicating
> code that way.  Any suggestions or examples that anyone can share?
>
> --
> Kevin Walzer
> Code by Kevin/Mobile Code by Kevin
> http://www.codebykevin.com
> http://www.wtmobilesoftware.com
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss@python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to