How do you add breakpoints to a Python program in IDLE?
Asked Answered
F

4

42

I solved this already, I'm just posting it here because I couldn't figure it out with google, or by reading the docs. I only found it by accident.

To add a breakpoint, right-click on the line that you want to add a breakpoint on and select "Set Breakpoint". The line will become highlighted. (Note that this only works when you are editing a file; it does not work at the interpreter.)

This site has a detailed tutorial about using the IDLE debugger.

On Mac, you need to Control-click instead of right clicking.

Franfranc answered 6/6, 2011 at 0:31 Comment(0)
G
13

Completing the answer supplied by the OP: after setting the breakpoint - you must turn on IDLE Shell's debug mode (using debug --> debugger). When you run the program, press "Go" in the debug window that opens up and IDLE will stop at the breakpoint.

IDLE Shell is the window that appears when you hit F5 to run your Python script.

enter image description here

Gianna answered 16/4, 2014 at 14:3 Comment(2)
Just to clarify this answer... In the Python shell you click on Debug, then check off Debugger. A dialog box opens. Then after you run or hit F5 to start your script, you click the "Go" button in the debugger window. I noticed that if you set a break point on an empty line, it will blow right through it. You have to set it on the first actual line of code that you don't want to run.Hagiography
I found this tutorial helpful as well: cs.uky.edu/~keen/help/debug-tutorial/debug.htmlPahlavi
R
8

There is an open Python issue about the lack of documentation for IDLE breakpoints. Contributions welcome!

Update: The on-line documentation and the IDLE help files (for 2.7.4, 3.2.4, and 3.3.0) have been updated, with Nick's help.

Rattlebrained answered 6/6, 2011 at 2:40 Comment(2)
Where do you submit a patch to documentation? I looked on the IDLE page, but there's no edit button. I looked at the sourceforge page, but it says they moved to python.org. I looked at the main page (and several subpages) but didn't see anything. What am I missing?Franfranc
If you login to the Python bug tracker and then view the linked issue (bugs.python.org/issue10405), you should see a "Comment" text field and a "Choose file" button to select a file to upload.Rattlebrained
A
5

You can set breakpoint before it is run.

  1. Set the breakpoint by right clicking on the relevant line of your program
  2. On your python shell, look for Debug - [Debug On] will be shown in your IDLE Python shell
  3. Go back to your program and press F5(hotkey) to run the program, it will stop in the relevant break line(s)
  4. If you want to look at some global variables or line of codes, you can check the box in the debugger
Airdry answered 20/1, 2016 at 2:39 Comment(4)
That's not trueKyungkyushu
@Grezzo, I have updated my comment, was not very proficient back then. thanks for the feedback. hope now it is better. i m trying to helpAirdry
I appreciate you trying to help :-)Kyungkyushu
Thanks! can you please amend the usefulness of my answer?Airdry
A
2

Just adding to this answer (would've commented but for the rules that say I don't have enough reputation to do so): On the Mac you must control-click. The normal "right-click" at least for the trackpad does not work to bring up the contextual menu with the option to set a breakpoint.

Amundsen answered 12/12, 2014 at 3:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.