PyQT5 ile sistem tepsisine ikon ekleme

aliorhun

Ali Orhun Akkirman

Posted on February 23, 2020

PyQT5 ile sistem tepsisine ikon ekleme

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)



Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
aliorhun
Ali Orhun Akkirman

Posted on February 23, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

PyQT5 ile sistem tepsisine ikon ekleme