python - illegal hardware instruction : When pynput and PyQt are combined - Stack Overflow

I was writing code to automatically click the mouse,zsh: illegal hardware instructionLibraryFramew

I was writing code to automatically click the mouse,

zsh: illegal hardware instruction  /Library/Frameworks/Python.framework/Versions/3.12/bin/python3 

error.
I thought it might be a problem with the combination of Pynput and PyQt, so I added the following code (when a button is clicked, the key pressed afterwards is displayed in the console).
The same error occurred, so I still think the combination is bad.
The screen starts up, but when I press a button, it crashes and throws an error.
The VSCode debugger does not say anything.
The environment is Mac OS Sonoma, Intel Mac.
The following is the source code.

from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QPushButton
from pynput import keyboard
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("test")

        grid = QGridLayout()
        self.setLayout(grid)

        self.testbut = QPushButton("テスト")
        self.testbut.clicked.connect(self.function)
        grid.addWidget(self.testbut, 0, 0)
    
    def function(self):
        listener = keyboard.Listener(on_press=self.on_press)
        listener.start()

    def on_press(self, key):
        print(key.char)

qAp = QApplication(sys.argv)
mainwindow = Window()
mainwindow.show()
qAp.exec()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745654414a4638458.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信