leafleafleafDocy banner shape 01Docy banner shape 02Man illustrationFlower illustration

Introduction to Python IDLE (Intensive Edition)

Estimated reading: 6 minutes 109 views
Introduction to python IDLE

For simple programs, we can do it on the command line and get the desired result very intuitively. However, when we close Python and reopened it, the previous code was lost. How can we make the computer remember what we typed?

When actually developing a program, we always use an integrated development environment (IDE) to write code, and then save the written code to a file. When we want to use the code, we can open the file and run Python on the file, so that the code can be executed repeatedly.

Introduction to IDLE

An Integrated Development Environment (IDE) is a tool software that contains all the basic tools a programmer needs to write and test programs. An integrated development environment typically contains a source code editor, a compiler or interpreter, and a debugger.

In the process of learning Python programming, we also have to come into contact with IDE. These Python development tools can help developers speed up development and improve efficiency.

IDLE is an integrated development environment that comes with Python. It has basic IDE functions, including basic components such as interactive command lines, editors, and debuggers. It is sufficient for the development of most simple applications.

When we install Python, IDLE is automatically installed, and there is no need to install it separately.

IDLE provides a very simple development environment for beginners to easily write and execute Python programs. IDLE has two main windows, the command line window and the editor window.

Next, we look at how to use IDLE to write programs.

Programming with Python IDLE

In a Windows environment, there are several ways to start IDLE. You can either directly enter python the command to open the Python Shell command line window in the Windows command line window as described above, or you can start IDLE through the shortcut menu or desktop icon, as shown in Figure 1.

Open IDLE in the Windows start menu
Open IDLE in the Windows start menu

Figure 1: Opening IDLE in the Windows Start Menu
The interface after IDLE is started is shown in Figure 2.

IDLE startup interface - Robort Heaven
IDLE startup interface

Figure 2: IDLE startup interface
In the IDLE window, you can select the “New File” command under the “File” menu to open a new file window, as shown in Figure 3.

Create new file window python - Robort
Create new file window python

Figure 3: Create New File Window
A new blank window will pop up, as shown in Figure 4.

IDLE pops up a new file window - Coding180
IDLE pops up a new file window

Figure 4: New file window popped up by IDLE
You can see that there is nothing in this window, it is waiting for us to enter a command. We call this window the “Program” window to distinguish it from the compiler window. We can enter the required commands in the program window. Here, enter the same code print("HelloWorld!")that we entered in the command line window earlier, as shown in Figure 5.

Enter code in IDEL
Enter code in IDEL

Figure 5: Entering the code in IDEL
It should be noted that there are no >>>prompt symbols in the command line window, because these symbols are not part of the program. The compiler window knows that we are currently working in the compiler window through these prompt symbols, but when we edit a separate file, we need to remove these auxiliary symbols imported by the compiler.

Next, select the “File” menu “Save” command to save the file, as shown in Figure 6.

python idle save new file - coding180
python idle save new file – coding180

Figure 6: IDLE save file button
Because it is a new file, the “Save As” dialog box will pop up, in which we can specify the file name and save location. After saving, the filename is automatically displayed in the blue title bar at the top of the screen. If there is unsaved content in the file, an asterisk *appears before and after the file name in the title bar.

Save the file to the specified directory. The path we choose is the D:\Python Programs\ch01file name 1.1, as shown in Figure 7.

Save the file to the specified location
Figure 7: Save the file to the specified location
We have saved this program, how to run this program next? Select the “Run Module” command in the “Run” menu, as shown in Figure 8.

python run idle module
python run idle module

Figure 8: Running the program using the Run Module command
You can get the running result of this program, and you can see the printed “Hello World!” in the compiler window, as shown in Figure 9

hello world result python
hello world result python

Figure 9: Program running effect

Other features of IDLE

IDLE has very rich functions, some of which are worth knowing and experiencing, because when writing programs, it is likely to be used.

1) IDLE supports syntax highlighting

The so-called syntax highlighting is to use different colors to display different elements of the code. We have seen the effect from the screenshot above.

By default, keywords are shown in orange, strings are shown in green, definitions and interpreter output are shown in blue, and console output is shown in brown. IDLE automatically applies these colors for highlighting as we enter code.

The benefit of syntax highlighting is that users can more easily distinguish between different syntax elements, thereby improving readability; at the same time, syntax highlighting also reduces the possibility of errors. For example, if the input variable name is displayed in orange, then you need to pay attention, which means that the name conflicts with the reserved keywords, so you must change the name of the variable.

2) IDLE supports keyword auto-completion

After the user enters a part of a keyword, such as one p, he can select the “Expand Word” command from the “Edit” menu, or directly press the Alt+/key combination, as shown in Figure 10, the keyword can be automatically completed.

Use the Expand Word command
Use the Expand Word command coding180

Figure 10: Using the Expand Word command
Here, what we get is print, as shown in Figure 11.

python expand word result - robort
python expand word result

Figure 11: IDLE autocompletion for print
Sometimes, we only remember the first few letters of a function, but not the full function name, what should we do? For example, we have an input() function that accepts standard input data and returns a value of type string. If we only vaguely remember the in and forget the put behind, at this time, I can select the “Show Completions” command of the “Edit” menu, or directly press the Ctrl+spacekey combination, as shown in Figure 12.

python show completion - coding180
python show completion

Figure 12: Using the Show Completions command
IDLE will then give some hints, as shown in Figure 13.

python show completion input - robort Heaven
python show completion input

Now IDLE will autocomplete this function name whenever you press enter. If the currently selected function is not the function we want, you can also use the up and down arrow keys to find it.

IDLE also has some other functions, which will not be described in detail here, and will be further introduced when used later in this tutorial. If readers are interested in more functions of IDLE, they can check the help manual by themselves.