mouse
mouse copied to clipboard
cannot unhook a class method
double click to give a test
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import subprocess
import os
import sys
import threading
import mouse
class Window(QMainWindow):
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.resize(800, 600)
mouse.on_click(self.setUpSearchBar)
mouse.on_double_click(lambda: mouse.unhook(self.setUpSearchBar))
def setUpSearchBar(self):
self.toolBar = QToolBar()
if __name__ == "__main__":
app = QApplication(sys.argv)
webEngineView = Window()
webEngineView.show()
sys.exit(app.exec_())
Exception :
Traceback (most recent call last):
File "C:\Users\i\AppData\Local\Programs\Python\Python38\lib\site-packages\mouse\_generic.py", line 23, in invoke_handlers
if handler(event):
File "C:\Users\i\AppData\Local\Programs\Python\Python38\lib\site-packages\mouse\__init__.py", line 169, in handler
callback(*args)
File "K:\BaiduYunDownload\programming\Python\PyQt_test.py", line 18, in <lambda>
mouse.on_double_click(lambda: mouse.unhook(self.setUpSearchBar))
File "C:\Users\i\AppData\Local\Programs\Python\Python38\lib\site-packages\mouse\__init__.py", line 234, in unhook
_listener.remove_handler(callback)
File "C:\Users\i\AppData\Local\Programs\Python\Python38\lib\site-packages\mouse\_generic.py", line 76, in remove_handler
self.handlers.remove(handler)
ValueError: list.remove(x): x not in list