473,503 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

returning control back to calling function

3 New Member
Hello friends,

I have a problem, I implemented a class which uses tkinter and displays the window as required, the class will create a window with listbox and inserts some items into it, I created the instance of this class and executed, I require the selected item to be sent back to the calling function, and the window should not be destroyed. When the button is pressed I require the control to get back to calling function and process further, but the problem is unless I close this tkinter window the control is not returned to the calling class. Can any one suggest solution how to handle this.






Description:

calling program:
1.create instance of tkinter class
2.get the selected item and process further.



Called tkinter class:
1. display the window,with items placed in list box, user selects the item,

require the control to be sent to step 2 of calling program when a button on tkinter class is pressed.

In general case,the control is only transferred when we close the tkinter gui window. Please suggest the solution.


regards,
sumanth
Nov 16 '06 #1
2 2775
bartonc
6,596 Recognized Expert Expert
Hello friends,

I have a problem, I implemented a class which uses tkinter and displays the window as required, the class will create a window with listbox and inserts some items into it, I created the instance of this class and executed, I require the selected item to be sent back to the calling function, and the window should not be destroyed. When the button is pressed I require the control to get back to calling function and process further, but the problem is unless I close this tkinter window the control is not returned to the calling class. Can any one suggest solution how to handle this.






Description:

calling program:
1.create instance of tkinter class
2.get the selected item and process further.



Called tkinter class:
1. display the window,with items placed in list box, user selects the item,

require the control to be sent to step 2 of calling program when a button on tkinter class is pressed.

In general case,the control is only transferred when we close the tkinter gui window. Please suggest the solution.


regards,
sumanth
Your stipulation "the window should not be destroyed" makes it tough.
TKs mainloop() must run (and won't return). If you look at the way IDLE is set up, you'll set that it is possible to start a gui in a seperate thread and communicate with the calling process. That gives you the treading module, the queue module, etc to study. OR

In a word: data persistance (well two words). You can use pickle or sql database (or text file for that matter) saved by the gui. Then, after mainloop() returns when the window is destroyed, you can retrieve the data. Then recreat the window and call mainloop() when you need it again.
Nov 16 '06 #2
bartonc
6,596 Recognized Expert Expert
Your stipulation "the window should not be destroyed" makes it tough.
TKs mainloop() must run (and won't return). If you look at the way IDLE is set up, you'll set that it is possible to start a gui in a seperate thread and communicate with the calling process. That gives you the treading module, the queue module, etc to study. OR

In a word: data persistance (well two words). You can use pickle or sql database (or text file for that matter) saved by the gui. Then, after mainloop() returns when the window is destroyed, you can retrieve the data. Then recreat the window and call mainloop() when you need it again.
In wxPython, the gui spawns the worker thead and wx.CallAfter() always runs in the main thread. Here is sample code form Robin Dunn's book (although I don't like all the practices used here, it does demo the threading module nicely):

Expand|Select|Wrap|Line Numbers
  1.  
  2. import wx
  3. import threading
  4. import random 
  5. class WorkerThread(threading.Thread):
  6.     """
  7.     This just simulates some long-running task that periodically sends
  8.     a message to the GUI thread.
  9.     """
  10.     def __init__(self, threadNum, window):
  11.         threading.Thread.__init__(self)
  12.         self.threadNum = threadNum
  13.         self.window = window
  14.         self.timeToQuit = threading.Event()
  15.         self.timeToQuit.clear()
  16.         self.messageCount = random.randint(10,20)
  17.         self.messageDelay = 0.1 + 2.0 * random.random()
  18.     def stop(self):
  19.         self.timeToQuit.set()
  20.     def run(self):
  21.         msg = "Thread %d iterating %d times with a delay of %1.4f\n" \
  22.              % (self.threadNum, self.messageCount, self.messageDelay)
  23.         wx.CallAfter(self.window.LogMessage, msg)
  24.         for i in range(1, self.messageCount+1):
  25.             self.timeToQuit.wait(self.messageDelay)
  26.             if self.timeToQuit.isSet():
  27.                 break
  28.             msg = "Message %d from thread %d\n" % (i, self.threadNum)
  29.             wx.CallAfter(self.window.LogMessage, msg)
  30.         else:
  31.             wx.CallAfter(self.window.ThreadFinished, self)
  32.  
Nov 16 '06 #3

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

Similar topics

2
1943
by: jeff | last post by:
I have a php file that contains a couple of arrays used for state/country pull-down lists. I have two global arrays and an accessor method for each. I have some simple logging methods, so I know a...
4
7215
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
3
1834
by: Carramba | last post by:
hi! the code is cinpiling with gcc -ansi -pedantic. so Iam back to my question Iam trying to make program were I enter string and serach char. and funktion prints out witch position char is...
8
2058
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling:...
9
5187
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore...
36
2234
by: MC felon | last post by:
how do we return strings or arrays from a function? i tried.. char some_func() //where i thought char would tell the compiler that the return is a string { char str; //something; return...
23
2898
by: pauldepstein | last post by:
Below is posted from a link for Stanford students in computer science. QUOTE BEGINS HERE Because of the risk of misuse, some experts recommend never returning a reference from a function or...
8
2188
by: darren | last post by:
Hi everybody, have a quick look at this code: ===== ===== int main(void) { string msg; makeString(msg); cout << "back in main, result = " << msg << endl;
160
5736
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
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
5566
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,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
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
3160
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
1495
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
729
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.