Skip to content

RPi: Editing Text files and Python Scripts with Raspbian

Getting Started

There are a myriad of ways to edit text files and code built into the Raspbian distribution; several even inside the terminal. But here we will cover some of the easier to use graphical programs.

It’s important you know your way around the terminal before continuing, please see the terminal tutorial -> here

Editing config files with leafpad

Leafpad is a lightweight notepad-like text editor that is bundled with Raspbian; we will use it here to edit simple config files in the file system.
For example the led ring tutorial directs us to edit the /boot/config.txt and comment out some lines.
To do this navigate to the /boot/ directory in the terminal; and then run ‘sudo leafpad config.txt’, this is similar to other commands you have seen taking a path as an argument, the important difference is the ‘sudo’ prefix which tells the terminal to run this command as a ‘super user’. This allows us to overwrite important system files and access gpio pins ect. You’ll have to use it often but you should still be careful.

We get an editor window like notepad on windows, we can insert a ‘#’ before dptparam to comment it out, and then save with control s
after exiting the editor you will regain control of your terminal.

Editing and running python scripts with Thonny

Next we can use a slightly complicated editor, Thonny is specifically for python ‘.py’ files and has some features that make debugging scripts easier.
Thonny can be found in the menu in the top left corner, or again opened from the terminal with ‘sudo thonny’.
Most scripts accessing the GPIO require sudo powers to work correctly, so its best to get used to running it as sudo.
You open a file to edit by navigating to it in the thonny gui; like notepad on windows.


We can enter python scripts line by line into the main window, and at any moment run our script with F5 or the gui button (green arrow).
Here is what it looks like to run a simple program inside thonny.
note the output in the lower window, this is the result of pressing F5 or the run button

Back To Top