Advertisement
Guest User

SysTray App

a guest
Oct 27th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import sys
  2. from PyQt4 import QtGui, QtCore
  3.  
  4. class SystemTrayIcon(QtGui.QSystemTrayIcon):
  5.     def __init__(self, icon, parent=None):
  6.         QtGui.QSystemTrayIcon.__init__(self, icon, parent)
  7.  
  8.         menu = QtGui.QMenu(parent)
  9.         exitAction = menu.addAction("Exit")
  10.         helloAction = menu.addAction("Hello World")
  11.  
  12.         self.setContextMenu(menu)
  13.         QtCore.QObject.connect(exitAction, QtCore.SIGNAL('triggered()'), self.exit)
  14.         QtCore.QObject.connect(helloAction, QtCore.SIGNAL('triggered()'), self.hello)
  15.  
  16.     def exit(self):
  17.         QtCore.QCoreApplication.exit()
  18.  
  19.     def hello(self):
  20.         msg = QtGui.QMessageBox.information(QtGui.QMessageBox(), "Hello", "Hello World")
  21.  
  22. def main():
  23.     app = QtGui.QApplication(sys.argv)
  24.  
  25.     w = QtGui.QWidget()
  26.     trayIcon = SystemTrayIcon(QtGui.QIcon("qtLogo.png"), w)
  27.  
  28.     trayIcon.show()
  29.     sys.exit(app.exec_())
  30.  
  31. if __name__ == '__main__':
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement