w3resource

Python IDLE

Introduction

IDLE is an integrated development environment (an application like a word processor which helps developers to write programs) for Python. IDLE is the Python IDE which comes with Python, built with the tkinter GUI toolkit. It has two modes Interactive and Development.

IDLE features:

  • Cross Platform : Works on Unix and Windows.
  • Multi-window text editor with syntax highlighting and smart indent and other.
  • Python shell window with syntax highlighting.
  • Integrated debugger.
  • Coded in Python, using the tkinter GUI toolkit

Python IDLE: Interactive Mode

Let us assume that we've already installed Python (here we installed Python 3.2 on a standard pc with windows 7 OS). Click on start button and find Python 3.2 tab in installed programs.

Python 3.2 idle in windows

 

Now clicking on Python 3.2 tab you can see the Python program development tool named IDLE (Python GUI).

Start Python 3.2 idle in windows

 

To start IDLE click on IDLE (Python GUI) icon, you will see a new window opens up and the cursor is waiting beside '>>>' sign which is called command prompt.

Python Shell

 

This mode is called interactive mode as you can interact with IDLE directly, you type something (single unit in a programming language) and press enter key Python will execute it, but you can not execute your entire program here. At the command prompt type copyright and press enter key Python executes the copyright information.

Python Interpreter

 

Now Python is ready to read new command. Let's execute the following commands one by one.

Command -1 : print("Hello World")
Command -2 : primt("Hello World")

The first command is correct and but the second one has a syntax error, here is the response from Python.

Hello World Python

 

Before go to Development mode see the details of Python IDLE Menus

File Menu

  • New window: Create a new editing window. Shortcut key : Ctrl+N
  • Open : Open an existing file. Shortcut key : Ctrl+O
  • Recent Files : List of recently open files.
  • Open module : Open an existing module. Shortcut key : Alt+M
  • Class browser : Show classes and methods in the current file. shortcut key : Alt+C
  • Path browser : Show sys.path directories, modules, classes, and methods.
  • Save : Save current window to the associated file. Shortcut key : Ctrl+S
  • Save As : Save current window to new file, which becomes the associated file. Shortcut key : Ctrl+shift+S
  • Save Copy As : Save current window to a different file without changing the associated file. Shortcut key : Alt+shift+S
  • Print window. Shortcut key : Ctrl+P
  • Close : Close current window (asks to save if unsaved). Shortcut key : Alt+F4
  • Exit : Close all windows and quit IDLE (asks to save if unsaved). Shortcut key : Ctrl+Q

Edit Menu

.
  • Undo : Undo last change to current window (max 1000 changes). Shortcut key : Ctrl+Z
  • Redo : Redo last undone change to current window. Shortcut key : Ctrl+shift+Z
  • Cut : Copy selection into system-wide clipboard; then delete the selection. Shortcut key : Ctrl+X
  • Copy : Copy selection into the system-wide clipboard. Shortcut key : Ctrl+C
  • Paste : Insert system-wide clipboard into the window. Shortcut key : Ctrl+V
  • Select All: All Select the entire contents of the edit buffer. Shortcut key : Ctrl+A
  • Find... : Open a search dialog box with many options. Shortcut key : Ctrl+F
  • Find again : Repeat last search. Shortcut key : Ctrl+G
  • Find selection : Search for the string in the selection. Shortcut key : Ctrl+F3
  • Find in Files... : Open a search dialog box for searching files. Shortcut key : Alt+F3
  • Replace...: Open a search-and-replace dialog box. Shortcut key : Ctrl+H
  • Go to line : Ask for a line number and show that line. Shortcut key : Alt+G
  • Expand word : Expand the word you have typed to match another word in the same buffer; repeat to get a different expansion
  • Show call tip. Shortcut key : Ctrl+backslash
  • Show surrounding parentheses. Shortcut key : Ctrl+0
  • Show completions. Shortcut key : Ctrl+space

Shell Menu

  • View Last Restart. Shortcut key : F6
  • Restart shell. Shortcut key : Ctrl+F6

Debug Menu

  • Go to file/line look around the insert point for a filename and line number, open the file, and show the line.
  • Debugger
  • Stack viewer shows the stack traceback of the last exception
  • Auto open stack viewer.

Options Menu

  • Configure IDLE

Windows Menu

  • Zoom height. Shortcut key : Alt+2
  • Python shell.

Help Menu

  • About IDLE.
  • IDLE Help.
  • Python Documents. Shortcut key : F1

Python IDLE : Development mode

At first, start with a new window.

python idle development-mode new window

 

Clicking on "New window" under file menu a new window will come. Type print "Hello World" in the new window.

python-idle-new-window

 

Let's save (Save command is located under the File menu) the file now. We save the program as helloworld.py under E:/python-programs folder.

How to save file in Python IDLE

 

To run the program select Run menu.

python idle run

 

Now click on Run Module or press F5 as a shortcut key to see the result.

helloworld.py output

 

Python IDLE: Syntax and Shell Colors

Syntax Color Shell Color
Keywords Orange Console output Brown
Strings Green Stdout Blue
Comments Red Stderr Dark green
Definitions Blue Stdin Black

Python command line interface

There are some users who prefer command line intersection, rather than a GUI interface. To go Python command line, click on Python 3.2 tab then click on Python(command line).

Python command line

 

Here is the screen shot of Python command line interface. To return type exit() or Ctrl+Z plus Enter key.

python command prompt

 

Previous: Python Installation
Next: CGI Programming

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.