05th-week experiment: simple graphic user interface design

Source: Internet
Author: User

What is Gui

GUI is the abbreviation of graphical user interface. In the GUI, you can not only type text and return text, but also view Windows, buttons, text boxes, and other graphics. You can also click the mouse and enter text on the keyboard.

First Gui

Code list6-1SmallGuiProgram"Hello, world"

Run the program and you will see the following interface (may be a little slow)

OK. We can use the following table to explain it row by row.Code list6-1Content:

APP = wx. app ()

Each wxpython application is a wx. app instance.

Wx. Frame (none, wx. id_any, "hello ")

Wx. frame is a top-level window. It has no parent window, so its parent is none. We also need to name this top-level window, that is, ID, wx. id_any.

Frame. Show (true)

Show id_any window

App. mainloop ()

Finally, we use the mainloop () function to keep the program running. We can also process events during running.

6.3 More complicated Gui

Step 1: Build a simple window

First, we construct a simple window (framework) with an editable text box. To build a text box, you need to use wx. textctrl widgets (similar to auto parts ). By default, the text box is a single line field, but the Wx. te_multiline parameter allows you to enter multiple lines of text.

Code list6-2A simple Editor

 
运行程序,你会看到下面的界面

Now you can't understand a lot of content in the code, because the code class involves the class myframe (wx. frame), special method _ init _ () and its attributes. You just need to know about it. We will talk about it later. Next we will continue to improve this applet and add a menu to the editor.

Step 2: Add a menu bar and status bar

Each application should have a menu bar and status bar. Let's add them to the editor.

Code list6-3Menu Bar and status bar of the Editor

 
 
运行程序,你会看到下面的界面:

It seems that the code is getting more and more complicated!

Yes. For Beginners, do not try to understand every line of code.

Gui Event in

This example is related to an event. What is an event?

In the GUI, the actions performed by the user (such as clicking a menu) are called events. A program RESPONSE event is called event processing. When some events occur (click a button, text input, move the mouse, and so on ). We need to program to respond to these events. The following program binds the event of an object using the BIND () method (what is an object ?)

We created a window with a text box to show the mouse position, which helps us understand the event.

This program uses a text box to display the current position of the mouse. the user's mouse movement is an event, and some programs must respond to the user's mouse movement events, such as in computer games, the star of the gun is targeted by moving the mouse.

Code list6-4Show the mouse position

Run the program and you will see the following interface

6.5 Complex events

Okay, let's take a look at the last example. The knowledge of other guis will be learned later.

This example is related to the event: There are two text boxes, three button controls, you can press the button to send messages between left and right.

Run the program and you will see the following interface

Code list6-5Send message(Copy) Source code

05th-week experiment: simple graphic user interface design

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.