How do I interact with a wxPython program

A compelling feature of Python compared to other programming languages is that it can be used in two ways: you can use it to run existing programs written in the Python language, or you can run Python interactively from a command prompt. Running Python interactively is similar to having a conversation with the Python interpreter. You type in a line of code and hit Enter. Python executes the code, responds, and prompts you for the next line. It is this interactive mode that sets Python apart from languages such as C + + , Visual Basic, and Perl. Because of the Python interpreter, there is no need to write an entire program in wxPython to do simple things. In fact, you can even use interactive Python as your desktop calculator.

In listing 4.1 we've started Python from the command line and entered some mathematical calculations. Python begins by displaying a few lines of information, followed by its primary prompt (>>>). When you enter something that requires additional lines of code, Python displays its secondary prompt (...).

Listing 4.1 A sample Python interactive session

$ Python

Python 2.3.3 (#1, Jan 25 2004, 11:06:18) [GCC 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)] on linux2

Type "help", "copyright", "credits" or "license" for more information. >>> 2 + 2

How do I interact with a wxPython program?

Interactive Python is not only a good desktop calculator, it is also a great learning tool, because it provides immediate feedback. When in doubt, you can simply launch Python, type in a few lines of throwaway code, see how Python reacts, and adjust your main code accordingly. One of the best ways to learn Python, or to learn how existing Python code works, is to try it interactively.

Was this article helpful?

0 0


  • Ines
    How to launch a python session from wxpython?
    5 years ago

Post a comment