最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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()
Post a comment

comment list (0)

  1. No comments so far