开发者

How to make a universal Python application

Can you make a universal python application that will run on both OSX and W开发者_如何学JAVAindows? With the same menu system, etc? Or would you need to make different versions for each OS?


I have built several cross platform applications (Windows / OS X) with wxPython. Practically all of the code translates flawlessly across the two platforms. To put into context, I usually develop the applications on Mac OS side, and if I spend let's say one week hammering out an application, I spend something like a few hours to get it running nicely in Windows.

Usually those hours consist of:

  • Tweaking minor wxPython visuals (font sizes, colors)
  • Making nice things like embedded icons
  • Keyboard shortcuts (CMD vs CTRL)
  • Main menu

Like you correctly point out, if you want identical main menus you have some work ahead of you on OS X side. I myself have never really bothered, I am fine with having some additional OS X default main menu bits and pieces.

The main menu thing aside though, considering how little tweaking you have to do, I'd say wxPython is the way to go. Together with px2exe on Windows side and py2app on OS X side it packs quite the punch.


Yes. You could build it with Qt for its interface and then you'll have to make judicious use of the os library to make sure that everything plays nicely no matter what operating system it's running on. However when it comes to packaging it for distribution, you'll have to do them separately. For Windows you can use py2exe, which will build a binary package which bundles in the Python runtime and all the libraries you use. I'm not sure how it works in Mac though.


You can try some of cross-platform tools e.g. Appcelerator Titanium Desktop supports python based development.


I'm currently developing an app on my Ubuntu Linux machine. I real life it runs on a windows xp machine with touchpad.

I'm using wxPython as the gui toolkit. In the past I've used .net predominantly but I wanted cross platform.

It really runs without any checks about which os it is running on. (save one check where i read a textfile and i have some trouble with the line endings)


To add on to what has already been given ...

If you rely on any os.system calls, you could also run into places where your code needs to handle the different platforms, well, differently.

As an example, I have an application which has a Help menu option which opens up a pdf file. My code would be like:

if arch.find("indows"):
    os.system("start " + help_filename)
elif arch.find("inux"):
    os.system("xdg-open " + help_filename)
else: # really this is the Mac case
    os.system("open " + help_filename)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜