[Wxpython study]wx. Callafter and Wx.futurecall

Source: Internet
Author: User

[Wxpython study]wx. Callafter and Wx.futurecall

The functions of the two Wxpython learned today: Wx.callafter and Wx.futurecall. This is a two unrelated function, but it's somewhat connected. Remember in the mailing list that someone asked:

The frame in Wxpython has no events like OnShow, because he wants to perform some action after the window is displayed. It was answered that using the Postevent () method.

This is really a method, but you have to create the event yourself (you can use an out-of-the-box event) and then bind the event to the processing window. I haven't tried this method. But now find a more convenient way to WX. Callafter:

Wx. Callafter (callable, *args, **kwargs)

In fact, this method is also using postevent () to achieve. After this method is executed, an event is added to the main event loop and then processed through the event loop. This is actually an asynchronous method for a non-GUI process to invoke a GUI method, or a child thread to invoke a method of the main thread, or to invoke another event handler asynchronously in an event handler, and the above question. This method is easy to use and does not require custom events, binding events, post events.

Again, WX. Futurecall:

Wx. Futurecall (milliseconds, callable, *args, **kwargs)

It is from WX. Timer, the function of which is to execute a method after the specified time.

To give a simple example, you can run a look at:

Import Wxclass Frame (WX.    FRAME): "" "Frame class." "" def __init__ (self, parent=none, id=-1, title= ' title ', Pos=wx.        Defaultposition, size= (+)): "" "Create a Frame instance." " Wx. Frame.__init__ (self, parent, ID, title, pos, size) self.text_id = wx. NewId () Self.text = WX. Textctrl (self, self.text_id) Self.text.Bind (WX. Evt_right_up, self. Onrightclick, id=self.text_id) Self.statusbar = self. Createstatusbar (1, 0) wx. Callafter (Self.call, 1, ' abc ', Name= "CCC", help= "test") wx. Futurecall (Self.call, ' call following 100ms ', name= "test") def onrightclick (Self, event): WX. MessageBox ("message window", "message", WX.) OK, self) def call (self, *args, **kwargs): message = repr (args) + repr (Kwargs) self. Setstatustext (message, 0) class App (WX.    APP): "" "Application class." "" def OnInit (self): Self.frame = FRAME ()-self.frame.Show () self. Settopwindow (SELF.FRAME) return Truedef main (): app = App () app. Mainloop () if __name__ = = ' __main__ ': Main ()

The red words above are important. The first two lines are an example of a call that will not be called until the frame is created. The second line is called after 5 seconds. The call function is used to display parameter information on the status bar.

[Wxpython study]wx. Callafter and Wx.futurecall

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.