473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to loop and call a function?

1 New Member
Hi all,


I want to loop and call a function every 1000 milliseconds with wx.CallLater. I implemented this (see below), but it does not factor in the delay - it seems to execute automatically. How can I get this to wait 1000 milliseconds between function calls?

This function is within a class. In my main module, I instantiate an object of this class and call the task_loop function. I intend to keep the loop going until will_break is set to True, and task_loop returns the work_session_agenda in the main module.

Thanks ahead!!!
Jul 3 '19 #1
3 35384
gits
5,390 Recognized Expert Moderator Expert
how does your code look like so far?
Jul 3 '19 #2
Vanisha
25 New Member
To loop and call a function, you can use a loop construct, such as a for loop, while loop, or do-while loop, to iterate over a set of values and call a function within the loop body. Here is an example using a for loop:
// Define the function
function myFunction($value) {
// Do something with the value
echo "The value is: $value <br>";
}

// Loop over a set of values and call the function
for ($i = 0; $i < 5; $i++) {
myFunction($i);
}
If you want to learn PHP or any other technologies, join CETPA Infotech.
Mar 23 '23 #3
vipulguptaseo
22 New Member
To call a function repeatedly with a delay of 1000 milliseconds using wx.CallLater, you need to make sure that the function is called again after the delay has passed. Here's an example of how you can achieve this within a class:

import wx

class MyClass:
def __init__(self):
self.will_break = False

def task_loop(self):
# Perform some task
self.do_something()

if not self.will_break:
# Call the task_loop function again after the delay
wx.CallLater(1000, self.task_loop)

def do_something(self):
# Your code to perform the task goes here
print("Doing something...")

# Instantiate the class
my_object = MyClass()

# Start the task loop
my_object.task_loop()

# Start the event loop in wxPython
app = wx.App()
app.MainLoop()

In this example, the task_loop function is initially called manually to start the loop. Inside the function, the task is performed (replace self.do_something() with your actual task implementation). Then, if the will_break flag is not set to True, the task_loop function is scheduled to be called again after the delay of 1000 milliseconds using wx.CallLater(1000, self.task_loop). This ensures that there is a delay between function calls.

The event loop (app.MainLoop()) in wxPython is started to allow the wx.CallLater to work correctly. It handles the internal processing of events and timers in the GUI framework.

Make sure to set self.will_break = True when you want to stop the loop and exit the program.

Note: Ensure that you have the necessary dependencies installed, including wxPython, to run this code successfully.
Jun 9 '23 #4

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

Similar topics

5
652
by: Lucy Randles | last post by:
I've written a VBA function that I then need to call in a form. Previously to do this I have written the call procedure in the same module as the function - i.e. Function callfunctionname() Call...
2
10175
by: PawelR | last post by:
Hello Group, In my application I have few class, and I want call function with "master class". This is as master form (startClass) and option window (ClassA). My question is how call function...
4
2836
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
2
3028
by: moondaddy | last post by:
I'm using vb.net and have an aspx page where I want to call a function in the code behind to do something on the backend and I want to call this function from a jscript function in the aspx page. ...
7
2670
by: Tiraman | last post by:
Hi , I have 3 files , middle.aspx file include the header.aspx and footer.aspx files . in each of the include files there is a function and from some reason the call to the Footer() function...
12
5752
by: leaf | last post by:
Hi, How to call function at runtime, based on a struct that contains the information for the function call: struct func_to_call { int function_id; // function id to call unsigned int nparams;...
5
40528
by: yaru22 | last post by:
Hi. I'm wondering if there is a way to call function that a variable refers to. I was writing a script to load xml file. And what I've written so far looks like this: var xmlDoc; ...
1
5152
by: Khai Doan | last post by:
I have function A, which need to call function B with the exact same argument list. What is the correct way to do this? I had function A: function A { B(arguments); } but it does not...
9
4699
by: Andrew Poulos | last post by:
Say I have this: var foo = function(x, y) { return x + y; }; var bar = function(fname, param1, param2) { /* * how do I call the function "foo" * and pass parameters to it?
1
3308
by: intermanch | last post by:
how call function php($varible) into javascript withod ajax: <!-- this code only call funnctions php but how call function php intermanch@gmail.com www.intermanch.blogfa.com
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.