最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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()
发布评论

评论列表(0)

  1. 暂无评论