DEV Community

loading...

PyQT5 ile sistem tepsisine ikon ekleme

Ali Orhun Akkirman
"Omnia mutantur, nihil interit"
・1 min read

PyQT5 kullanarak basit bir sistem tepsisi uygulaması geliştirebilmek için aşağıdaki gibi bir kod yazmak gerekmektedir:

Alt Text

import sys
from PyQt5 import QtCore, QtGui, QtWidgets

# code source: https://stackoverflow.com/questions/893984/pyqt-show-menu-in-a-system-tray-application  - add answer PyQt5
#PyQt4 to PyQt5 version: https://stackoverflow.com/questions/20749819/pyqt5-failing-import-of-qtgui

class SystemTrayIcon(QtWidgets.QSystemTrayIcon):

    def __init__(self, icon, parent=None):
        QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
        menu = QtWidgets.QMenu(parent)
        exitAction = menu.addAction("Exit")
        self.setContextMenu(menu)
        menu.triggered.connect(self.exit)

    def exit(self):
        QtCore.QCoreApplication.exit()


def main(image):
    app = QtWidgets.QApplication(sys.argv)

    w = QtWidgets.QWidget()
    trayIcon = SystemTrayIcon(QtGui.QIcon(image), w)

    trayIcon.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    on=r'/usr/share/ornekuygulama/deneme.png' # ADD PATH OF YOUR ICON HERE .png works
    main(on)

Discussion (0)