Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QCoreApplication::exec: The event loop is already running
- File "systray_icon_NumLk_on_off.py", line 21, in on_key_press
- main(on)
- File "systray_icon_NumLk_on_off.py", line 46, in main
- sys.exit(app.exec_())
- SystemExit: -1
- #####get the state of NumLk key
- from win32api import GetKeyState
- from win32con import VK_NUMLOCK
- #how to use: print(GetKeyState(VK_NUMLOCK))
- #source: http://stackoverflow.com/questions/21160100/python-3-x-getting-the-state-of-caps-lock-num-lock-scroll-lock-on-windows
- #####Detect if NumLk is pressed
- import pyglet
- from pyglet.window import key
- window = pyglet.window.Window()
- #source: http://stackoverflow.com/questions/28324372/detecting-a-numlock-capslock-scrlock-keypress-keyup-in-python
- on=r'on.png'
- off=r'off.png'
- @window.event
- def on_key_press(symbol, modifiers):
- if symbol == key.NUMLOCK:
- if GetKeyState(VK_NUMLOCK):
- #print(GetKeyState(VK_NUMLOCK))#should be 0 and 1 but
- main(on)
- else:
- main(off)
- @window.event
- def on_draw():
- window.clear()
- ### display icon in systray
- import sys
- from PyQt5 import QtCore, QtGui, QtWidgets
- #source: http://stackoverflow.com/questions/893984/pyqt-show-menu-in-a-system-tray-application - add answer PyQt5
- 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)
- 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__':
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement