Hello All,
can someone tell me exactly what is done by this function?

Thanks alot!

Recommended Answers

All 6 Replies

It is used with events in wxPython. If you have a button lets say that when you press it pops up a dialog box. But there is also something else going on and you want the method that makes that dialog box to be called After the event function is done.

So here is the example from http://wiki.wxpython.org/CallAfter

import threading,wx


class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
        panel = wx.Panel(self, -1)
        mainSizer.Add(wx.Button(panel, ID_RUN, "Click me"))
        mainSizer.Add(wx.Button(panel, ID_RUN2, "Click me too"))
        wx.EVT_BUTTON(self, ID_RUN, self.onRun)
        wx.EVT_BUTTON(self, ID_RUN2, self.onRun2)

    def onRun(self,event):
        print "Clicky!"
        wx.CallAfter(self.AfterRun, "I don't appear until after OnRun exits")
        s=raw_input("Enter something:")
        print s

    def onRun2(self,event):

    def __run(self):
        wx.CallAfter(self.AfterRun, "I appear immediately (event handler\n"+ \
                        "exited when OnRun2 finished)")
        s=raw_input("Enter something in this thread:")
        print s

    def AfterRun(self,msg):
        dlg=wx.MessageDialog(self, msg, "Called after", wx.OK|wx.ICON_INFORMATION)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "CallAfter demo")
        return True

app = MyApp(0)

So If I want let say to execute YouWin() method and when it is done I want to execute another method let me call it MeWin(),
How do I do? What Arguments does it need?

Thanks for reply

you would call wx.CallAfter(self.MeWin,ARGUMENTS) and then that will call the function after the YouWin function is done.

Lastly, what Arguments does it take. Will they be MeWin() method arguments or there are other? I mean wx.CallAfter(self.MeWin(), ARGUMENTS) what exactly ARGUMENTS is?

Woops, should have called them paramaters. If you have any that are needed then you put them as the second paramater but if there are no paramaters needed for the MeWin method then you dont need to have a second paramater.
Note that you dont put parentheses after the self.MeWin the the wx.CallAfter.

commented: Brilliant Boy! +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.