Python GUI interface

Python GUI Interface

In this chapter, you’ll learn about some popular Python integrated development environments (IDEs) and how to use them to develop programs.

To use Python’s scripting mode, you need to save a sequence of Python instructions in a text file with a .py extension. You can use any text editor on your operating system. Whenever the interpreter encounters an error, you need to edit the source code and run it again. To avoid this tedious process, use an IDE. An IDE is a one-stop solution for entering and editing source code, detecting errors, and executing programs.

IDLE

Python’s standard library includes the IDLE module. IDLE stands for Integrated Development and Learning Environment. As the name suggests, it’s very useful when you’re learning. It includes a Python interactive shell and a code editor tailored to the needs of the Python language structure. Some of its key features include syntax highlighting, auto-completion, and a customizable interface.

To write Python scripts, open a new text editor window from the File menu.

Python GUI interface

Opens a new editing window where you can enter Python code. Save it and run it from the Run menu.

Python GUI Interface

Jupyter Notebook

Originally developed as a web interface for IPython, Jupyter Notebook supports multiple languages. The name itself is composed of the letters of the supported languages – Julia, PYhon, and R. Jupyter Notebook is a client-server application. The server is started on the local host, and the browser acts as its client.

Install Jupyter Notebook using PIP –

pip3 install jupyter

Invoke from the command line.

C:UsersAcer>jupyter notebook

The server starts on port 8888 on localhost.

Python GUI interface

Your system’s default browser will open a link to http://localhost:8888/tree to display the dashboard.

Python GUI interface

Opens a new Python notebook. It displays IPython-style input cells. Enter Python commands and run the cells.

Python GUI interface

Jupyter Notebook is a versatile tool widely used by data scientists to display inline data visualizations. The notebook can be easily converted and distributed in PDF, HTML, or Markdown formats.

VS Code

Microsoft has developed a source code editor called VS Code (Visual Studio Code) that supports multiple languages, including C++, Java, Python, and others. It provides features such as syntax highlighting, auto-completion, a debugger, and version control.

VS Code is free software. You can download and install it from: https://code.visualstudio.com/

Launch VS Code from the Start menu (on Windows).

Python GUI interface

You can also launch VS Code from the command line –

C:test>code .

You can’t use VS Code unless you have the corresponding language extension installed. The VS Code Extension Marketplace has extensions for many language compilers and other useful tools. From the Extensions tab (Ctrl+Shift+X), search for the Python extension and install it.

Python GUI Interface

After activating the Python extension, you need to set the Python interpreter. Press Ctrl+Shift+P and select the Python interpreter.

Python GUI interface

Open a new text file, enter the Python code, and save the file.

Python GUI interface

Open a command prompt terminal and run the program.

Python GUI Interface

PyCharm

PyCharm is another popular Python IDE. Developed by the Czech software company JetBrains, its features include code analysis, a graphical debugger, and integration with version control systems. PyCharm supports web development with Django.

Both the Community and Professional editions can be downloaded from the following URL: https://www.jetbrains.com/pycharm/download .

Download and install the latest version: 2022.3.2 and open PyCharm. The welcome screen is shown below −

Python GUI Interface

When you start a new project, PyCharm creates a virtual environment for it based on the selected folder location and selected Python interpreter version.

Python GUI Interface

You can now add one or more Python scripts required for your project. Here, we’ll add some sample Python code to the main.py file.

Python GUI Interface

To execute the program, select it from the Run menu or use the Shift+F10 shortcut.

Python GUI interface

The following is the output displayed in the console window –

Python GUI interface

Leave a Reply

Your email address will not be published. Required fields are marked *