[Python] wxPython status bar component, message dialog box component learning Summary (original), pythonwxpython

Source: Internet
Author: User

[Python] wxPython status bar component, message dialog box component learning Summary (original), pythonwxpython
1. Status Bar components 1. Basic Introduction

:

      

The status bar is displayed in the red box.

It can be divided into several blocks. For example, if the upper part is divided into two blocks and the proportion is fixed, you can specify

Each block can display information. Generally, the content of each block is updated in real time by binding events.

In addition to displaying text messages, you can add other components, such as progress bars (commonly used), buttons, edit boxes, and so on.

I have learned these things at present, and I hope I can tell them in my comments if I have not mentioned them. Thank you.

2. Basic creation process (there are two types) 1. Create a status bar object and add it to the window frame.

The Basic Process Code is as follows:

        

First, create a status bar object (id =-1 indicates that the id is automatically and randomly generated by the system), and then set its:

Number of partitions: It seems that many partitions can be set. Must be greater than 0; otherwise, an error is returned.

Block proportion: the parameter is a tuples, the number of parts is several, and the element in the element group is several.

[-N,-m]. When a negative value is used, the block is n: m.

[N, m], an integer indicates that the block size is a fixed value. The length of 0th blocks is n, and the size of 1st blocks is m, which does not change with the change of the window frame.

Content displayed in a part: It is generally set in the real event. There are two parameters, the first is the content, and the second is the block index (starting from 0)

Finally, add it to the window frame.

2. instantiate a status bar object from the window frame and perform operations

        

You can control the status bar by accepting the status bar object returned by the window frame. CreateStatusBar () method.

Consistent Control Setting Process

3. Others 1. When the status bar object does not need to be displayed, you can call the. Show () method of the status bar object to set it.

        

Parameters:

When True,

If False, this parameter is hidden.

It is generally less useful, but it is still necessary to know.

2. Add a progress bar to the status bar component.

The method is simple:

Declare a parent file as the progress bar of this status bar.

Then, adjust and set your own location and size based on the relevant size parameters of the parent file.

Generally, the window size change event is bound to the window to reflect the real-time progress bar and parent size. (The following code does not bind events)

 

1 # coding: UTF-8 2 # author: Twobox 3 4 import wx 5 6 class MyWin (wx. frame): 7 def _ init _ (self, parent, title): 8 super (MyWin, self ). _ init _ (parent = parent, title = title) 9 self. initUI () 10 self. show () 11 12 def initUI (self): 13 statusBar = self. createStatusBar (id =-1) 14 statusBar. setFieldsCount (2) 15 16 print (statusBar. getSize () 17 gauge = wx. gauge (statusBar, range = 100, pos = (2, 2), size = (statusBar. getSize () [0]/2-13, 22), style = wx. GA_HORIZONTAL) 18 gauge. setValue (50) # set the current progress to the event. Update 19 20 def main (): 21 app = wx in real time. app () 22 MyWin (None, "Windows-test") 23 app. mainLoop () 24 25 if _ name _ = '_ main _': 26 main ()

 

4. Status Bar component learning code

 

1 # coding: UTF-8 2 # author: Twobox 3 4 import wx 5 6 class Mywin (wx. frame): 7 "2 methods" 8 def _ init _ (self, parent, title): 9 super (Mywin, self ). _ init _ (parent = parent, title = title) 10 self. initUI_2 () 11 self. show () 12 13 def initUI_1 (self): 14 "" creates a StatusBar object and adds it to the current window. "15 self. statusBar1 = wx. statusBar (self,-1) # instantiate a status bar object 16 self. statusBar1.SetFieldsCount (2) # set the number of chunks in the status bar to 17 self. statusBar1.SetStatusWidths ([-4,-1]) # Set the ratio of block in the status bar to 18 self. statusBar1.SetStatusText ("1st rows, 1st columns", 1) # Set the content in the status bar. The index starts from 0 to 19 self. setStatusBar (self. statusBar1) # Add the status bar object to the window body. 20 21 def initUI_2 (self): 22 "StatusBar2 is used directly as an object created in the current window. "" 23 self. statusBar2 = self. createStatusBar () # create a status bar object through the current window frame 24 self. statusBar2.SetFieldsCount (2) # Same as 25 self. statusBar2.SetStatusWidths ([-4,-1]) 26 self. statusBar2.SetStatusText ("1st rows, 1st columns", 1) 27 self. statusBar2.Show (True) # can be set to hide (that is, invisible) 28 29 def main (): 30 app = wx. app () 31 Mywin (None, "StatusBar-Test") 32 app. mainLoop () 33 34 if _ name _ = '_ main _': 35 main ()

 

2. message dialog box component 1. Basic Introduction

:

      

This information box is accessible almost every day. For example, if you close a software, it will pop up a box asking you if you want to close it, or if you want to run it immediately after installing a software, etc.

The general composition of message boxes:

Title: "Hello World!" on the left of the X key !"

Message icon: an exclamation point

Message content: Text in a pure white box ~

It can be multiple rows. It is also possible for O. O to enable 10 thousand line breaks.

There are several buttons: one. There are four buttons:

YES, NO, CANCEL, and OK.

After you click the button, the following four representations are returned, so you can determine which button to press.

Wx. ID_YES, wx. ID_NO, wx. ID_CANCEL, wx. ID_ OK.

2. General use process

The following events are bound to a button, and the event function is triggered when clicked:

      

First, create a message box object:

Message: the content of the message box.

Caotion: Message Box title

Style: Specifies the button type and message box icon style (for a list of acceptable style parameters, see below)

A judgment statement:

This judgment statement first executes the. ShowModal () method of the information box (that is, this information box is displayed ).

When the button is related to a single machine, this method returns an identifier.

Finally, we need to complete the different operations based on the received representation.

3. Others (style acceptable parameter descriptions)

        

The wx. ICON _ *** is the ICON style of the information box.

Others are the button styles in the information box.

4. Information Box learning code (interesting)

 

1 # coding: UTF-8 2 # author: Twobox 3 4 import wx 5 6 class MyWin (wx. frame): 7 def _ init _ (self, parent, title): 8 super (MyWin, self ). _ init _ (parent = parent, title = title) 9 self. initUI () 10 11 def initUI (self): 12 panel = wx. panel (self) 13 vbox = wx. boxSizer (wx. VERTICAL) 14 15 # Add two Button16 self. bt1 = wx. button (parent = panel, label = u "") 17 self. bt2 = wx. button (parent = panel, label = u "close") 18 self. bt1. Bind (wx. EVT_BUTTON, self. eventButtonOne) 19 self. bt2.Bind (wx. EVT_BUTTON, self. eventButtonTwo) 20 21 vbox. add (self. bt1, proportion = 1, flag = wx. EXPAND | wx. ALL, border = 5) 22 vbox. add (self. bt2, proportion = 1, flag = wx. EXPAND | wx. ALL, border = 5) 23 24 panel. setSizer (vbox) 25 26 self. center () 27 self. show () 28 29 def eventButtonOne (self, event): 30 msgDialog = wx. messageDialog (parent = None, message = u "Have you been there today? (Can only say yes) ", caption = u" Hello World! ", Style = wx. OK) 31 if msgDialog. showModal () = wx. ID_ OK: 32 self. bt1.SetLabel (u "Answer: Today is good") 33 else: 34 self. bt1.SetLabel (u "Answer: Today is not good") 35 36 def eventButtonTwo (self, event): 37 msgDialog = wx. messageDialog (parent = None, message = u "are you sure you want to close this window? ", Caption = u" Hello World! ", Style = wx. YES_NO | wx. ICON_AUTH_NEEDED) 38 if msgDialog. showModal () = wx. ID_YES: 39 self. close () 40 self. bt2.SetLabel (u "option: Do not close") 41 42 def main (): 43 app = wx. app () 44 MyWin (None, "MessageDialog-Test") 45 app. mainLoop () 46 47 if _ name _ = '_ main _': 48 main ()

 

3. Feelings

O. O is so tired and tired that if you try to finish it slowly, you may miss lunch .. I strongly condemn the change in school canteen meals .. More comfortable ..

The use of these two components is not difficult. The main role of this article is to summarize the basic usage, so that you can take a look at it later.

O. O wxpython has less systematic information on the Internet .. Ah...

4. Postscript

Notes for reference in information box: http://www.cnblogs.com/dyx1024/archive/2012/07/07/2580380.html

Reprinted please indicate the source (● 'authorization' ●): http://www.cnblogs.com/Twobox/

12:35:23

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.