Setting a breakpoint in your script is done by clicking on the left vertical gray bar in the editor pane. It will place a small, inconspicuous white circle in the editor border. You can also set and unset breakpoints during a debugging session.
Setting a breakpoint (the small white circle left to ‘print i').
Now, if you start debugging the script, and press the Continue button, the script will run until it arrives at the print i line. The output will show up in the Python Interpreter window, if you have it open.
Now that you know how breakpoints work, I'll show a good way to use them.
In GUI programming, breakpoints are often the only way of debugging code that becomes activated after the main loop has started. Let's look at the following script, where there is a bug in the code that is activated when the button is pressed:
# # button.py # from qt import * import sys class MainWindow(QMainWindow): def __init__(self, *args): apply(QMainWindow.__init__, (self,) + args) self.setCaption("Button") self.grid=QGrid(2, self) self.grid.setFrameShape(QFrame.StyledPanel) self.bn=QPushButton("Hello World", self.grid) self.bn.setDefault(1) self.connect(self.bn, SIGNAL("clicked()"), self.slotSlot) self.setCentralWidget(self.grid) def slotSlot(self): i = 1/0 def main(args): app=QApplication(args) win=MainWindow() win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__=="__main__": main(sys.argv)
If you try to single-step until you've arrived at the bug, you will be stepping for a long time. It is easier to continue the application until it hits the breakpoint in slotSlot(), and take it from there by hand.