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

delay function [in wxPython]

P: 34
Hi,
I need to add some delay function to my code where on clicking the exit button some text needs to be displayed on the text area..
Right now the text is not not appearing coz there s no dealy between 2 events of closing and displaying text.

following is my code for exit and i need to add a pause or delay between two events:
Expand|Select|Wrap|Line Numbers
  1. def OnExit(self, event):
  2.         # wxGlade: MyFrame.<event_handler>
  3.         display2=language_processor.thanks()
  4.         self.text_ctrl_2.SetValue(display2)
  5.         self.Close()
  6.         event.Skip()
May 2 '07 #1
Share this Question
Share on Google+
7 Replies


bartonc
Expert 5K+
P: 6,596
Hi,
I need to add some delay function to my code where on clicking the exit button some text needs to be displayed on the text area..
Right now the text is not not appearing coz there s no dealy between 2 events of closing and displaying text.

following is my code for exit and i need to add a pause or delay between two events:
Expand|Select|Wrap|Line Numbers
  1. def OnExit(self, event):
  2.         # wxGlade: MyFrame.<event_handler>
  3.         display2=language_processor.thanks()
  4.         self.text_ctrl_2.SetValue(display2)
  5.         self.Close()
  6.         event.Skip()
Expand|Select|Wrap|Line Numbers
  1. wx.FutureCall(5000, self.Close)
instead of
Expand|Select|Wrap|Line Numbers
  1. self.Close()
will wait 5 seconds and the call Close().
May 2 '07 #2

P: 34
Expand|Select|Wrap|Line Numbers
  1. wx.FutureCall(5000, self.Close)
instead of
Expand|Select|Wrap|Line Numbers
  1. self.Close()
will wait 5 seconds and the call Close().
Hi,
Thanx for the suggestion ,It worked !
Now i want to add one more thing that is when i click the button some text is to be displayed on text control for a minute and after that i need to hide it or remove it..
Do i have a function for that??
Expand|Select|Wrap|Line Numbers
  1. def OnPress(self, event):
  2.         # wxGlade: MyFrame.<event_handler>
  3.         display2=language_processor.message()
  4.         self.text_ctrl_2.SetValue(display2)
  5.         wx.FutureCall(5000, ??)
??--What shud be the function here to hide the text??
May 3 '07 #3

bartonc
Expert 5K+
P: 6,596
Hi,
Thanx for the suggestion ,It worked !
Now i want to add one more thing that is when i click the button some text is to be displayed on text control for a minute and after that i need to hide it or remove it..
Do i have a function for that??
Expand|Select|Wrap|Line Numbers
  1. def OnPress(self, event):
  2.         # wxGlade: MyFrame.<event_handler>
  3.         display2=language_processor.message()
  4.         self.text_ctrl_2.SetValue(display2)
  5.         wx.FutureCall(5000, ??)
??--What shud be the function here to hide the text??
Please not the addition of [ CODE ] tags! Instructions for their use are in "REPLY GUIDELINES" on the right hand side of the page (while replying).

Any object that inherits from wx.Window (like wx.TextCtrl) has a Hide() method. Just def a function, put something like:
Expand|Select|Wrap|Line Numbers
  1. thisTextCtrl.Hide()
in it and call it with wx.FutureCall().
May 3 '07 #4

P: 34
Hi,

I found one function time.sleep(sec) for delaying only.But im not getting how to implement it in my code to solve my purpose of displaying the text for 15 sec and then hiding it!
Expand|Select|Wrap|Line Numbers
  1. def help(self,event):
  2.         display3="hello"
  3.         time.sleep(15)
  4.         self.text_ctrl_3.SetValue(display3)
  5.  
  6.         time.sleep(5)
  7.         display3=""
  8.         self.text_ctrl_3.SetValue(display3)
Why the above not solving my purpose??
May 4 '07 #5

bartonc
Expert 5K+
P: 6,596
Hi,

I found one function time.sleep(sec) for delaying only.But im not getting how to implement it in my code to solve my purpose of displaying the text for 15 sec and then hiding it!
Expand|Select|Wrap|Line Numbers
  1. def help(self,event):
  2.         display3="hello"
  3.         time.sleep(15)
  4.         self.text_ctrl_3.SetValue(display3)
  5.  
  6.         time.sleep(5)
  7.         display3=""
  8.         self.text_ctrl_3.SetValue(display3)
Why the above not solving my purpose??
I've re-arranged the order of setting the text and then sleeping; you'll have to try it.
The problem may be that sleep() doesn't return control to the mainloop(), but you can try:
Expand|Select|Wrap|Line Numbers
  1. def help(self,event):
  2.         display3="hello"
  3.         self.text_ctrl_3.SetValue(display3)
  4.         self.text_ctrl_3.Update()  # might need to add this, might not
  5.         time.sleep(15)
  6.  
  7.         display3=""
  8.         self.text_ctrl_3.SetValue(display3)
  9.         self.text_ctrl_3.Update()  # might need to add this, might not
  10.         time.sleep(5)
May 4 '07 #6

P: 34
I've re-arranged the order of setting the text and then sleeping; you'll have to try it.
The problem may be that sleep() doesn't return control to the mainloop(), but you can try:
Expand|Select|Wrap|Line Numbers
  1. def help(self,event):
  2.         display3="hello"
  3.         self.text_ctrl_3.SetValue(display3)
  4.         self.text_ctrl_3.Update()  # might need to add this, might not
  5.         time.sleep(15)
  6.  
  7.         display3=""
  8.         self.text_ctrl_3.SetValue(display3)
  9.         self.text_ctrl_3.Update()  # might need to add this, might not
  10.         time.sleep(5)
Thanx,it worked !
May 5 '07 #7

bartonc
Expert 5K+
P: 6,596
Thanx,it worked !
You are welcome!
May 5 '07 #8

Post your reply

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