适用于任务栏(Win)和菜单(mac)功能的跨平台Python GUI?

Rab*_*ski 6 python user-interface taskbar cross-platform menubar

我是Python编程的新手,也是跨平台GUI构建的新手(以前的GUI体验只通过visual basic和Java).我已经编写了一些python代码来筛选来自网站的数据,现在我想构建一个GUI ,它将驻留在Mac OS X菜单栏和Window的任务栏(即系统托盘)中.

关于跨平台Python GUI的最有用的一般页面是这个(尽管它的名称指示窗口GUI).并且一些stackoverflow问题也很有用(特别是这个问题,以及关于拆分GUI和cli代码的这个问题的接受答案).我想我会选择wxPythonQT,因为我希望GUI看起来尽可能本地化.

但是,正如我所说,相当简单的GUI将主要存在于任务栏/菜单栏中.这会影响我的决定吗?

mar*_*ett 10

Here's an example for PyQt. This works for me on MacOS X; I haven't tried it on other platforms. Note that the QSystemTrayIcon class will raise exceptions if it doesn't have an icon – I grabbed the RSS feed svg from Wiki commons for my icon.svg (but you can give QIcon a PNG directly and not mess around with QtSvg).

import PyQt4
from PyQt4 import QtCore, QtGui, QtSvg

app = QtGui.QApplication([])

i = QtGui.QSystemTrayIcon()

m = QtGui.QMenu()
def quitCB():
 QtGui.QApplication.quit()
def aboutToShowCB():
 print 'about to show'
m.addAction('Quit', quitCB)
QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
i.setContextMenu(m)

svg = QtSvg.QSvgRenderer('icon.svg')
if not svg.isValid():
 raise RuntimeError('bad SVG')
pm = QtGui.QPixmap(16, 16)
painter = QtGui.QPainter(pm)
svg.render(painter)
icon = QtGui.QIcon(pm)
i.setIcon(icon)
i.show()

app.exec_()

del painter, pm, svg # avoid the paint device getting
del i, icon          # deleted before the painter
del app
Run Code Online (Sandbox Code Playgroud)


Bra*_*don 2

请参阅有关如何在 wxPython 中完成 Windows 系统托盘/OS X 菜单栏功能的相关 SO 答案。