Step 1 of wxPython

Source: Internet
Author: User

First Steps Step 1
In this part of the wxPython tutorial, we will create some simple examples
In this tutorial, we will create some simple examples.
Simple example
We start with a very simple example. Our first script will only show a small window. It won't do much. We will analyze the script line by line. Here is the code
Starting from the simplest example, the first piece of code only shows a small window. It doesn't matter. We will analyze the code in one row.
[Python] view plaincopy
Import wx
 
App = wx. App ()
 
Frame = wx. Frame (None,-1, "simple. py ")
Frame. Show ()
 
App. MainLoop ()
This is our first example.
Import wx: import the wxPython module.

App = wx. App (): required for each wxPython Program

Frame = wx. Frame (None,-1, "simple. py ")
Frame. Show ()
We create a frame, which is a wx. Frame
Then, call its Show () method to display it.

The last line enters the mainloop statement. This mainloop statement is an endless loop.


Wx. Frame
Wx. frame widget is one of the most important widgets in wxPython. it is a container widget. it means that it can contain in other widgets. actually it can contain any window that is not a frame or dialog. wx. frame consists of a title bar, borders and a central container area. the title bar and borders are optional. they can be removed by various flags.
Wx. Frame is the most important component in wxPython. It is a window that can contain other components. In fact, it can contain any window or dialog box. Wx. Frame includes a title bar, boundary, and central area. The title and boundary are optional.
Wx. frame has the following constructor. as we can see, it has seven parameters. the first parameter does not have a default value. the other six parameters do have. those four parameters are optional. the first three are mandatory.
Wx. Frame has the following constructor. As we can see, it has seven parameters. The first parameter has no default value. The other six parameters are available. Four parameters are optional. The first three parameters are mandatory.
[Python]
Wx. Frame (wx. Window parent, int id =-1, string title = '', wx. Point pos = wx. DefaultPosition,
Wx. Size size = wx. DefaultSize, style = wx. DEFAULT_FRAME_STYLE, string name = "frame ")
[Python] view plaincopy
Import wx
App = wx. App () www.2cto.com
 
Window = wx. Frame (None, style = wx. MAXIMIZE_BOX | wx. RESIZE_BORDER
| Wx. SYSTEM_MENU | wx. CAPTION | wx. CLOSE_BOX)
Window. Show ()
 
App. MainLoop ()

Looking at the code above, the window is not minimized during running.
Size and Position
We can specify the size of our application in two ways. We have a size parameter in the constructor of our widget. Or we can call the SetSize () method.
There are two ways to specify the program size: 1. Specify the size with the specified parameter; 2. Use the SetSize () method
[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()
In this example, the application will be 250x200 px
[Python] view plaincopy
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))

Similarly, we can specify the location of the program.
Move (wx. Point point): Move the window to the specified position.
MoveXY (int x, int y): Move the window to the specified position.
SetPosition (wx. Point point): Set the position of the window.
SetDimensions (wx. Point point, wx. Size): position and size

[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Move (800,250 ))
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()
Centering on the screen
If we want to center our application on the screen, wxPython has a handy method. the Centre () method simply centers the window on the screen. no need to calculate the width and the height of the screen. simply call the method.
Center the window:
[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Centre ()
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()


First Steps Step 1
In this part of the wxPython tutorial, we will create some simple examples
In this tutorial, we will create some simple examples.
Simple example
We start with a very simple example. Our first script will only show a small window. It won't do much. We will analyze the script line by line. Here is the code
Starting from the simplest example, the first piece of code only shows a small window. It doesn't matter. We will analyze the code in one row.
[Python] view plaincopy
Import wx
 
App = wx. App ()
 
Frame = wx. Frame (None,-1, "simple. py ")
Frame. Show ()
 
App. MainLoop ()
This is our first example.
Import wx: import the wxPython module.

App = wx. App (): required for each wxPython Program

Frame = wx. Frame (None,-1, "simple. py ")
Frame. Show ()
We create a frame, which is a wx. Frame
Then, call its Show () method to display it.

The last line enters the mainloop statement. This mainloop statement is an endless loop.


Wx. Frame
Wx. frame widget is one of the most important widgets in wxPython. it is a container widget. it means that it can contain in other widgets. actually it can contain any window that is not a frame or dialog. wx. frame consists of a title bar, borders and a central container area. the title bar and borders are optional. they can be removed by various flags.
Wx. Frame is the most important component in wxPython. It is a window that can contain other components. In fact, it can contain any window or dialog box. Wx. Frame includes a title bar, boundary, and central area. The title and boundary are optional.
Wx. frame has the following constructor. as we can see, it has seven parameters. the first parameter does not have a default value. the other six parameters do have. those four parameters are optional. the first three are mandatory.
Wx. Frame has the following constructor. As we can see, it has seven parameters. The first parameter has no default value. The other six parameters are available. Four parameters are optional. The first three parameters are mandatory.
[Python]
Wx. Frame (wx. Window parent, int id =-1, string title = '', wx. Point pos = wx. DefaultPosition,
Wx. Size size = wx. DefaultSize, style = wx. DEFAULT_FRAME_STYLE, string name = "frame ")
[Python] view plaincopy
Import wx
App = wx. App ()
 
Window = wx. Frame (None, style = wx. MAXIMIZE_BOX | wx. RESIZE_BORDER
| Wx. SYSTEM_MENU | wx. CAPTION | wx. CLOSE_BOX)
Window. Show ()
 
App. MainLoop ()

Looking at the code above, the window is not minimized during running.
Size and Position
We can specify the size of our application in two ways. We have a size parameter in the constructor of our widget. Or we can call the SetSize () method.
There are two ways to specify the program size: 1. Specify the size with the specified parameter; 2. Use the SetSize () method
[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()
In this example, the application will be 250x200 px
[Python] view plaincopy
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))

Similarly, we can specify the location of the program.
Move (wx. Point point): Move the window to the specified position.
MoveXY (int x, int y): Move the window to the specified position.
SetPosition (wx. Point point): Set the position of the window.
SetDimensions (wx. Point point, wx. Size): position and size

[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Move (800,250 ))
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()
Centering on the screen
If we want to center our application on the screen, wxPython has a handy method. the Centre () method simply centers the window on the screen. no need to calculate the width and the height of the screen. simply call the method.
Center the window:
[Python]
Import wx
Class Example (wx. Frame ):
Def _ init _ (self, parent, title ):
Super (Example, self). _ init _ (parent, title = title, size = (250,200 ))
Self. Centre ()
Self. Show ()
 
If _ name _ = '_ main __':
App = wx. App ()
Example (None, title = 'SIZE ')
App. MainLoop ()

Author: youyigong
 

Related Article

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.