3.11 stops without error message in QT callback

I like to use Idle to edit and test my program. But in 3.11, it does not provide error information unless the error is in init. After I select Run Module, if there is error, my program just crashes. But in the console, there is no any error message. I have to search line by line where the error might be.
Anyone has similar experience? How to fix it?

You situation sounds unusual, but you give too little information to say more. If you can reduce your program to the minimum number of lines needed to reproduce the problem, and post it, we might be able to say something.

The following is a simple example I copied from PyQt5 Signals, Slots and Events - pyqtSignal, pyqtSlot, Mouse Events & Context menus with additional print command. I have two print command lines in the program. If I intentionally misspell the print command in the function the_button_was_clicked(self):, the program crashes without any error message. If I change the print inside init, it gives me the following error which it is supposed to have:
Traceback (most recent call last):
File “C:/Users/xxxxx/Downloads/simple test.py”, line 26, in
window = MainWindow()
File “C:/Users/mk658473/Downloads/simple test.py”, line 20, in init
prin(‘I am here’)
NameError: name ‘prin’ is not defined. Did you mean: ‘print’?


import sys

from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton


# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")
        button = QPushButton("Press Me!")
        button.setCheckable(True)
        button.clicked.connect(self.the_button_was_clicked)

        # Set the central widget of the Window.
        self.setCentralWidget(button)

        prin('I am here')
    def the_button_was_clicked(self):
        print("Clicked!")

app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()
  1. Python has expressions and statements; it does not have commands. print is a function and print('abc') is an expression statement. ‘Commands’ are usually executed in a command-line terminal or console, such as a Linux Bash window or Windows Command Prompt console.

  2. I am fairly sure that IDLE has nothing to do with this issue. To test, run your program direct with Python with the command python path/to/app.py, possibly replacing python with python3 or py according you your OS and installation. If you have the same problem, remove ‘IDLE’ from the title.

  3. the_button_was_clicked is a callback executed by QT when you click the QT button. The handling of errors in widget callbacks, including where it sends any error messages, is done by the GUI framework. If you run your program without or even with IDLE in a command-line terminal, you might see a NameError displayed in the terminal. This is because sys.stderr for user code run by IDLE is None when IDLE is not started in a terminal and the terminal when IDLE is started in a terminal. Use python -m idlelib path/to/app.py for the latter.

  4. Debugging callback errors can by difficult. If possible, event handlers should be tested both directly and in use. (Your button click handler would be easy to test. Many others are harder.)

Thank you for explanation. I did not realize the way to handle error messages are different.

I changed the IDE from IDLE to Microsoft Visual Studio Code. Thanks God. It can provide error message in QT callback. It made me crazy when IDLE cannot provide error message even for a simple typo.