Using IDLE

We’ve been creating Python files, and adding code using a text editor. But there’s a better way. We can use an IDE. There are several to choose from, but we’ll use IDLE (Integrated Development and Learning Environment), the one that comes with Python.

IDLE is a simple IDE, without too many features. This makes it excellent to learn with!

Start by opening IDLE. It was installed when you installed Python, whether you use Linux or Windows.

When you open IDLE, the IDLE Shell window displays. This is the same as the Python shell that we’ve been using.

You can use this in the same way that you’ve been using the Python shell if you want to.

Or, you can click File > Open, and open the test_code.py file that we’ve been working on. File > New also works if you want to start something new.

When you open a file, the File Editor window opens. In this window, we can see the code that we’ve been writing.

Having two windows open is handy because we can put them side-by-side.

Notice that the code is coloured? Comments are red, functions are purple, and strings are green. This makes it nicer to look at.

Running Your Code

If you’re ready to run your code, first make sure you’ve saved your file. If your file name has asterisk symbols around it (as shown below), then your file hasn’t been saved yet.

When you’re ready, press F5 on your keyboard, or click Run > Run Module. The result of your code appears in the IDLE Shell window.

Error Detection

IDLE will also help you find errors in your code. For example, add this line of code:

print ('lets print a string)

Notice that we’ve deliberately made a mistake, by leaving out the final single-quote mark. What happens now when you save and try to run the file? IDLE tells you there’s a problem, and where to find it.

There are several advantages to using an IDE when writing code. You’ll find them as you use it more.