| | |
wx.CallAfter()
Thread Solved
![]() |
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
So here is the example from http://wiki.wxpython.org/CallAfter
python Syntax (Toggle Plain Text)
import threading,wx ID_RUN=101 ID_RUN2=102 class MyFrame(wx.Frame): def __init__(self, parent, ID, title): wx.Frame.__init__(self, parent, ID, title) panel = wx.Panel(self, -1) mainSizer=wx.BoxSizer(wx.HORIZONTAL) mainSizer.Add(wx.Button(panel, ID_RUN, "Click me")) mainSizer.Add(wx.Button(panel, ID_RUN2, "Click me too")) panel.SetSizer(mainSizer) mainSizer.Fit(self) 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): t=threading.Thread(target=self.__run) t.start() 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) dlg.ShowModal() dlg.Destroy() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, "CallAfter demo") frame.Show(True) frame.Centre() return True app = MyApp(0) app.MainLoop()
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
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
How do I do? What Arguments does it need?
Thanks for reply
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
you would call
wx.CallAfter(self.MeWin,ARGUMENTS) and then that will call the function after the YouWin function is done. Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
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?
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
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.
Note that you dont put parentheses after the self.MeWin the the wx.CallAfter.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
![]() |
Similar Threads
- (k)dialog or zenity implemented as a python function (Python)
- Wx Plot (Python)
- popup menu does not appear if wx.FileDialog is activated beforehand (Python)
Other Threads in the Python Forum
- Previous Thread: Computer picks a random word and player has to guess it.
- Next Thread: Translate C/C++ Code to python
| Thread Tools | Search this Thread |
alarm ansi anydbm app assignment backend beginner binary bluetooth character cipher cmd coordinates customdialog cx-freeze data decimals development directory dynamic exe feet file float format function generator getvalue gnu graphics halp handling heads homework http ideas input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path pointer prime programming progressbar push py2exe pygame pymailer python queue random recursion recursive schedule screensaverloopinactive script slicenotation sqlite ssh statistics string strings sudokusolver text thread time tlapse tuple ubuntu unicode url urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib xlwt






