Thonny Python IDE
repository·master·Indexed 26 days ago
https://github.com/thonny/thonnyA beginner-friendly Python IDE designed to help users learn programming concepts. Thonny supports various microcontrollers through dynamic board support configuration via JSON files and provides a specialized interface for beginners. The project includes documentation on Linux installation, Flatpak builds, macOS bundling, and a collaborative translation process using POEditor and Babel.
What's inside Thonny
- Thonny is an Integrated Development Environment (IDE) specifically designed for learning Python programming. It is intended for beginners to help them understand programming concepts through its specialized interface and features.
Use Assistant for error explanation and code investigation
masterThe Assistant view in Thonny provides two primary functions for debugging:
- Error Explanation: When a program terminates with an error, the Assistant attempts to explain the error in simpler terms and provides advice for locating and fixing the underlying issue.
- Code Investigation: For logic errors where no explicit error message is thrown, the Assistant suggests using
PylintandMypyto identify 'bad smells' or contradictions in the code.
- Mypy: Detects type contradictions (e.g., passing a string to a function expecting an integer).
- Pylint: Performs various code quality checks. Thonny includes a curated selection of relevant checks for beginners.
Understand how Thonny updates board support via JSON files
masterThonny uses JSON files located in the
data/directory to manage board variants. Because Thonny consults these files online (e.g., via GitHub), users can benefit from updates to board support and variants without needing to install a newer version of the Thonny software itself.- Modern Thonny versions (4.0b4 and later): Use
circuitpython-variants-*andmicropython-variants-*files. - Older Thonny versions: Use other JSON files in the directory.
Note for contributors: The
circuitpython-variants-*andmicropython-variants-*files are automatically generated by scripts. Do not edit them directly; if changes are required, please create a GitHub issue first.- Modern Thonny versions (4.0b4 and later): Use
Use Birdseye for post-execution value exploration
masterBirdseye operates differently from the built-in Thonny debugger. Instead of step-by-step execution with breakpoints, you run the script using Run → Debug current script (Birdseye).
Note the following behavior:
- Execution takes longer than a normal run.
- Breakpoints are ignored.
- You cannot step through the code manually.
- Once execution completes, Thonny opens a web page (served by a local Birdseye server) where you can inspect the execution process and how intermediate values were computed.
- Important: You do NOT need to import
birdseye.eyeor decorate your functions manually; Thonny handles the recording automatically.
Use Expert mode
masterExpert mode provides additional features useful for teaching and advanced workflows:
- Full Screen: Access via the View menu to enter full-screen mode.
- Maximize Editor/View: Double-click an editor or view tab to maximize it. Press ESC to unmaximize.
- Action Repeater: Access via the Tools menu (Tools → Open repeater...) to repeat user action logs.
Perform manual code review for debugging
masterWhen a program fails, you can perform a manual code review by mentally tracing the logic. Focus on the following elements:
Variables
- Does the name reveal its purpose?
- What type of values does it hold (e.g., strings, integers, lists)?
- What is its function (e.g., updating repeatedly, storing shared information)?
Loops
- Is the loop necessary?
- How many times should it execute and what does it depend on?
- Which code belongs inside vs. outside the loop?
- What setup/cleanup is required before and after the loop?
Complex Expressions
- What is the evaluation order, and does it match Python's behavior?
- What type of value should the expression return?
Missing Logic
- If different situations require different handling, you may need an
ifstatement. - If a task needs to be repeated, you may need a loop.
Update Flatpak Python dependencies
masterThonny's Flatpak dependencies are managed using the Flatpak Pip Generator. This tool generates JSON files for Python packages to be included in the Flatpak manifest's
modulessection.Note: If
org.freedesktop.Sdk//20.08is installed in both user and system installations, the generator may fail. It is recommended to temporarily remove one of them.Enable colorized output in the Shell
masterTo use ANSI escape codes for colored output, you must enable Terminal emulation mode in Tools => Options => Shell. Once enabled, you can use standard ANSI codes or libraries likecoloramato produce colored text.Validate the Thonny AppData file
masterBefore releasing a new version of Thonny on Linux, you must update the
org.thonny.Thonny.appdata.xmlfile with the new version, date, and a description of changes. Useappstreamclito validate the XML file to ensure it is correctly formatted for app stores.# Using system package manager sudo apt install appstream appstreamcli org.thonny.Thonny.appdata.xml # Using Flatpak flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo flatpak install --user flathub org.freedesktop.appstream-glib flatpak run org.freedesktop.appstream-glib validate org.thonny.Thonny.appdata.xmlUse "Faster" debug mode for larger programs
masterFor larger programs where the "Nicer" mode's overhead (like expression stepping and step-back capabilities) becomes too slow, use "Faster" mode.
This mode uses a more traditional debugging style. You can use Step over, Step into, Step out, and Resume, but you cannot use Step back.
Debug programs using print statements and Thonny's debugger
masterWhen a program is not working as expected, use these techniques to identify the cause:
- Print Debugging: Add
print()statements to track program execution and inspect variable states at specific points. This helps verify if Python has reached a certain line and what the current values of variables are.- If an expression is complex, break it down into smaller parts or introduce new variables to print them individually.
- Step-by-step Execution: For a more powerful approach, use Thonny's core feature: the debugger. This allows you to execute code line-by-line to observe the program flow and state changes in real-time.
Always aim to diagnose the exact reason for a malfunction before attempting to fix the code.
print("friends before for-loop", friends)- Print Debugging: Add
Anchor user windows for Turtle or Tkinter programs
masterWhen developing programs using
TurtleorTkinter, you can use the Ancrer les fenêtres utilisateur (Anchor user windows) option in the menu Lancer (Run menu) to manage window placement.When this option is enabled, Thonny performs the following:
- Remembers window positions: Thonny saves the locations of your windows and places them in the same position during subsequent runs.
- Maintains window focus: It ensures your Tkinter window stays on top. After the Tkinter window appears, Thonny automatically returns focus to the Thonny editor window so you can continue editing code immediately without using the mouse.
To run a new version of your program and replace the existing window, simply press
F5again.