I have the following thread class in my code: (I changed the names of the functions and variables for simplicity)
class Parent(threading.Thread):
def __init__(self, variable1, variable2):
threading.Thread.__init__(self)
self.SerialNo = SerialNo
self.cellNo = cellNo
def run(self):
function1(self.variable1, self.variable2)
function2(self.variable1, self.variable2)
In order to start the various threads, just as a starting point I had hardcoded values for variable1 and variable2 as follows:
Parent(“Hello”, 12).start()
Parent(“World”, 13).start()
In the main application the values of variable1 and variable2 will come in from a textbox entry in a GUI. The code for the GUI is a different python script.
How do I pass the value from the textbox in the other python script to this script? I’m just looking for some ideas on this one. I’m relatively new to wx/python.
Thanks in advance.
Hi Mike,
Thank you for the reply. So, the GUI has about 100 textboxes and I want to spawn a new thread everytime someone enters something in a particular textbox. For instance:
If someone enters something in textbox2, I spawn a thread. If someone enters something in textbox3 I spawn one more thread. All the threads have to execute the same set of functions listed under the run() method. I’ll go through the articles you mentioned. Thank you once again.
···
On Monday, November 11, 2013 2:39:45 PM UTC-8, Mike Driscoll wrote:
Hi,
On Monday, November 11, 2013 4:04:57 PM UTC-6, Abhishek Vedamoorthy wrote:
I have the following thread class in my code: (I changed the names of the functions and variables for simplicity)
class Parent(threading.Thread):
def __init__(self, variable1, variable2):
threading.Thread.__init__(self)
self.SerialNo = SerialNo
self.cellNo = cellNo
def run(self):
function1(self.variable1, self.variable2)
function2(self.variable1, self.variable2)
In order to start the various threads, just as a starting point I had hardcoded values for variable1 and variable2 as follows:
Parent(“Hello”, 12).start()
Parent(“World”, 13).start()
In the main application the values of variable1 and variable2 will come in from a textbox entry in a GUI. The code for the GUI is a different python script.
How do I pass the value from the textbox in the other python script to this script? I’m just looking for some ideas on this one. I’m relatively new to wx/python.
Thanks in advance.
When working with threads and wxPython, you can’t interact with wxPython directly. Instead, you’ll need to use thread-safe methods, such as wx.CallAfter or wx.PostEvent. You can use those to pass information from the thread back to the GUI.
You should read the following articles to get up to speed:
The second article shows how to use a wxPython thread-safe method in combination with pubsub to send data between classes. The first article has lots of interesting ways to create threads, queues, etc.
Mike