By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

wxMessageBox with an auto-close timer in wxPython

P: 15
Platform and Python installation info:

Platforms: Windows, OS X
Python: Active State Python 2.7
wxPython: Version 2.9


Here is a sample code in which I use a wxMessageBox:

Expand|Select|Wrap|Line Numbers
  1. import wx,os
  2.  
  3. class Frame(wx.Frame):
  4.     def __init__(self, parent, id, title):
  5.         wx.Frame.__init__(self, parent, id, title, size=(100, 100),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
  6.  
  7.         host=os.system('hostname')
  8.         if host!='superman':            
  9.             self.dialogBox=wx.MessageBox('The host name should be superman. Closing this dialog box in 2s...','Info')            
  10.             self.Destroy()
  11.         else:
  12.             self.Center()
  13.             self.Show()
  14.  
  15. if __name__ == '__main__':
  16.     app = wx.App(redirect=False)
  17.     frame = Frame(None, -1, 'Sample')
  18.     app.MainLoop()
According to the above piece of code, If the host name is not 'superman' , then the user is displayed a message box and prompted to press 'OK'. If the user presses 'OK' button on the message box, then the control moves to the next line in the code (i.e., line number 10) where the frame is destroyed. I want to be to able to automatically close the dialog box and go to the next line in the code i.e., self.Destroy() if the user does not press the 'OK' button in the next 2 seconds. Any thoughts on how do I do that in wxpython ?
May 16 '11 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 621
This requires threading or processing or using wx's timer class. This forum can probably offer more help but no one wants to waste time since this question has been posted on every forum in the known universe, so decide which you would like to use, post some code, and ask questions about that code.
May 16 '11 #2

P: 15
Sounds like a tough one to do.
Aug 29 '11 #3

Elias Alhanatis
P: 56
Try this:
1) Create a wx.timer object in your app.
2) Start the timer just before the wx.MessageBox appears
3) In the function that your timer calls , 'find' any 'wx.MessageBox' dialogs and 'Destroy' them , so execution continues.
DOnt know if it will work , but give it a try!!!!
Sep 22 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.