Introduction to Python Interactive Programming-Introduction to event-driven programming and python

Source: Internet
Author: User

Introduction to Python Interactive Programming-Introduction to event-driven programming and python

Traditional programming adopts the following linear model:

Start ---> code block A ---> code block B ---> code block C ---> code block D ---> ...... ---> end

Each code block contains code that completes various things, but programmers know the execution sequence of code blocks A, B, C, D... the only thing that can change this process is data. Enter different data and judge based on the Condition Statement. The process may be changed to A ---> C ---> E... --->. The running sequence of each program may be different, but its control process is determined by the input data and the program you write. If you know the current running status of the Program (including the input data and the program itself), you will know the running process of the program until it is completed.

For the event-driven program model, the process is roughly as follows:

Start ---> initialize ---> wait

Unlike the traditional programming mode above, the event driver waits after it is started. What are you waiting? Wait for the event to trigger. In traditional programming, there are also "Waiting". For example, in code block D, you define an input () that requires user input data. But this is different from the following waiting. In traditional programming, "waiting", such as input (), you as a program writer know or force users to enter something, maybe a number, it may be the file name. If the user inputs an error, you need to remind him and ask him to enter it again. The wait of the event driver is completely unknown, and does not force the user to enter or do anything. As long as an event occurs, the program will respond accordingly ". These events include the input information, the mouse, a key on the keyboard, and the system's Internal timer.

In Python, The simplegui module is used to implement program interaction. The structure is as follows:

 

The following is a simple Interactive Programming program:

 

 1 # Import the module 2 import simplegui 3  4 # Define global variables (program state) 5 counter = 0 6  7 # Define "helper" functions 8 def increment(): 9     global counter10     counter = counter + 111 12 # Define event handler functions13 def tick():14     increment()15     print counter16 17 # Create a frame18 frame = simplegui.create_frame("Test",100,100)19 20 # Register event handlers21 timer = simplegui.create_timer(1000,tick)22 frame.add_button("Click me!",tick)23 24 # Start frame and timers25 frame.start()26 timer.start()

 

 

  


Introduction to computer programming what is the python language?

Python is an object-oriented and interpreted computer programming language. It was invented by Guido van rosum at the end of 1989 and released in 1991 as the first public release. The Python syntax is concise and clear, and has rich and powerful class libraries. It is often called the glue language. It can easily connect various modules (especially C/C ++) made in other languages. A common application scenario is to use Python to quickly generate a prototype of a program (sometimes even the final interface of the Program) and then have a special requirement on it, rewrite with a more appropriate language. For example, if the graphic rendering module in 3D games has high performance requirements, you can rewrite it with C ++.
 
Is there anyone programming with python?

In the face of the eye-catching Pearl (Perl) light, the spirit snake (Python) is more powerful than ever before. It can run on a variety of OS such as MS-DOS, Amiga, BeOS, OS/2, VMS, QNX, etc. It is faster and better than Perl and VB, and it is more scalable than C and C ++; not only do they provide special effects and animation in super movies such as Star Wars and Star Trek, but they also break into the control room of the Space Administration of the United States. For details about the truth, see the report.

For the Perl (PEARL) language, Internet developers can be said to have no one knows, no one knows; it runs fast, easy to operate, and can make users feel happy when using it. However, when it is not satisfactory: Its openness brings about its complexity. When it is used to deal with large projects, it is especially difficult to start.

Despite this, most Internet projects still need to be built by the Perl "hero.

But there is no choice. The latest recommended software is Python (spirit snake), which has a history of only 1/4 of Perl and has many similar features.

The name of Python comes from the famous funny Monty Python, which has many well-known actors and creates a screen image that is well known to all.

So what is the image of Python in the Internet world?

Faster and better Python

Like Perl, Python is also an interpreted language. It adopts an object-oriented approach and its language structure is between C and Perl. Although it is regarded as a very high language, its built-in interpreter functions are very basic, and only a few functions, operators and keywords constitute the entire programming language. Its advantages are not only that, but also that it can be expanded through a series of modules. It is faster and better than Perl and VB statements, and more scalable than C and C ++ languages.

Similarly, Python first converts program statements into a series of byte code through an interpretation and compilation system, which is then processed by the Python virtual machine. Python is designed very effectively, mainly because of its large function library. Therefore, users do not need to enter the system environment or operating system, nor reference modules. Using Python programming, small programs are still small programs, and there is no need to spend too much time and cost.

In addition to its Core platform, Python can run on MS-DOS, Amiga, BeOS, OS/2, VMS, QNX, and many other operating systems. You can even run Python programs on your handheld computer.
In the face of the eye-catching Pearl (Perl) light, the spirit snake (Python) is more powerful than ever before.

In addition to its Core platform, Python can run on MS-DOS, Amiga, BeOS, OS/2, VMS, QNX, and many other operating systems. You can even run Python programs on your handheld computer.

Python also has the following notable features:

Strong adaptability

Python can be supported by a series of platforms. It is compiled in a complete format that can run on Windows, MacOS, and its own Tk expansion platform, and can be used to develop user-friendly interfaces. On UNIX and other platforms, Python can be compiled by programmers as source code, or used together with other pre-compiled binary codes. Its strong adaptability makes it more suitable for cross-platform applications: it can be used on Mac and PC machines without any modification when it writes program segment 95% on UNIX platforms. Expand the support of Tk platform, and even allow GUI-based applications to switch freely on the above three platforms without the need for great flexibility, while maintaining a unified interface.

Because of this inherent cross-platform running capability, Python can also support expansion platforms of some platforms, thus simplifying and eliminating the need to adapt to other languages and environments. Sun audio device and SGI version with SunOS/Solaris tool with audio and video interfaces (including... full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.