Re: Accelerator keys cross-platform

"Michael O'Donnell" <[email protected]>
Newsgroups gmane.comp.python.tkinter
Message-ID <CABaQFFHtpNzaxo6Ewj8UKn7rsV-ijC5kJ1yHnKAnc65Y0zGv8g@mail.gmail.com>
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 <[email protected]> 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
> [email protected]
> https://mail.python.org/mailman/listinfo/tkinter-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.