Python可以在多个平台上工作,可以用于桌面和web应用程序,因此我得出结论,有某种方法可以将它编译成Mac、Windows和Linux的可执行文件。

问题是我不知道从哪里开始或如何写一个GUI与它,谁能在这一点上提供一些光,并指出我在正确的方向请?


当前回答

你可以做三件事:

首先要做的是找到一个GUI设计器,它可以将其代码作为独立的应用程序(如.exe文件)启动。我使用MatDeck的一个版本(对于使用GUI设计器的人,我推荐MD Python设计器),因为我相信(我使用另一个版本,所以我不太确定。)它允许我将代码转换为独立的应用程序,这样,就不需要在每台PC上安装软件来运行程序。

The second option is partially bypassing the problem, launch the GUI as a web page. This would give you the most compatibility as most if not all OS can utilize it. Once again, you would need a GUI Designer that can convert its components into a web compatible format, I've done it once and I used the same version of MatDeck(Visionary Deck), I would not recommend MD Python Designer this time as I don't know if it can turn its GUIs into websites using web assembly whereas Visionary Deck I've tried and tested. As with all things there are most likely other software this is just one I use frequently because I work a lot with Mathematics and Physics.

第三种选择也可以绕过这个问题,但在Tkinter中进行,并确保您有一个Python IDE或只是普通的Python并运行代码,这将启动GUI。这是一个很好的解,可能是最简单的,但我不会把它归类为最短或最好的。如果你只打算在几个操作系统和电脑之间切换,这可能是你最好的选择。

其他回答

你可以做三件事:

首先要做的是找到一个GUI设计器,它可以将其代码作为独立的应用程序(如.exe文件)启动。我使用MatDeck的一个版本(对于使用GUI设计器的人,我推荐MD Python设计器),因为我相信(我使用另一个版本,所以我不太确定。)它允许我将代码转换为独立的应用程序,这样,就不需要在每台PC上安装软件来运行程序。

The second option is partially bypassing the problem, launch the GUI as a web page. This would give you the most compatibility as most if not all OS can utilize it. Once again, you would need a GUI Designer that can convert its components into a web compatible format, I've done it once and I used the same version of MatDeck(Visionary Deck), I would not recommend MD Python Designer this time as I don't know if it can turn its GUIs into websites using web assembly whereas Visionary Deck I've tried and tested. As with all things there are most likely other software this is just one I use frequently because I work a lot with Mathematics and Physics.

第三种选择也可以绕过这个问题,但在Tkinter中进行,并确保您有一个Python IDE或只是普通的Python并运行代码,这将启动GUI。这是一个很好的解,可能是最简单的,但我不会把它归类为最短或最好的。如果你只打算在几个操作系统和电脑之间切换,这可能是你最好的选择。

对于GUI本身:

PyQT基本上就是参考。

另一种开发快速用户界面的方法是编写web应用程序, 让它在本地运行,并在浏览器中显示应用程序。

另外,如果你选择lubos hasko建议的Tkinter选项 你可能想尝试portablepy让你的应用在Windows环境中运行 没有Python。

PySimpleGUI包装了tkinter,适用于Python 3和2.7。它还可以在Qt、WxPython和web浏览器上运行,在所有平台上使用相同的源代码。

您可以使用在tkinter中找到的所有相同的小部件(滑块、复选框、单选按钮……)来创建自定义gui。代码往往非常紧凑且可读。

#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
    import PySimpleGUI as sg
else:
    import PySimpleGUI27 as sg

layout = [[ sg.Text('My Window') ],
          [ sg.Button('OK')]]

window = sg.Window('My window').Layout(layout)
button, value = window.Read()

正如PySimpleGUI文档中所解释的,要构建运行的.EXE文件:

pyinstaller -wF MyGUIProgram.py

你不需要为Mac/Windows/Linux编译python。它是一种解释语言,因此您只需要在您选择的系统上安装Python解释器(它适用于所有三个平台)。

至于跨平台的GUI库,Python的Tk/Tcl小部件库工作得很好,我相信它足够跨平台。

Tkinter是Tk/Tcl的python接口

来自python项目网页:

Tkinter并不是唯一的GuiProgramming Python工具包。然而 最常用的一种,几乎是 只有一个是可移植的 Unix, Mac和Windows

由于python现在默认安装在几乎所有非windows操作系统上,你真正需要确保的唯一一件事就是你使用的所有非标准库都已安装。

话虽如此,构建包含python解释器和您使用的任何库的可执行文件是可能的。然而,这可能会创建一个大型可执行文件。

MacOS X甚至在Xcode IDE中支持创建完全独立的GUI应用程序。任何运行OS X的用户都可以运行这些程序。