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
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.
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): -
-
import wx
-
import threading
-
import random
-
class WorkerThread(threading.Thread):
-
"""
-
This just simulates some long-running task that periodically sends
-
a message to the GUI thread.
-
"""
-
def __init__(self, threadNum, window):
-
threading.Thread.__init__(self)
-
self.threadNum = threadNum
-
self.window = window
-
self.timeToQuit = threading.Event()
-
self.timeToQuit.clear()
-
self.messageCount = random.randint(10,20)
-
self.messageDelay = 0.1 + 2.0 * random.random()
-
def stop(self):
-
self.timeToQuit.set()
-
def run(self):
-
msg = "Thread %d iterating %d times with a delay of %1.4f\n" \
-
% (self.threadNum, self.messageCount, self.messageDelay)
-
wx.CallAfter(self.window.LogMessage, msg)
-
for i in range(1, self.messageCount+1):
-
self.timeToQuit.wait(self.messageDelay)
-
if self.timeToQuit.isSet():
-
break
-
msg = "Message %d from thread %d\n" % (i, self.threadNum)
-
wx.CallAfter(self.window.LogMessage, msg)
-
else:
-
wx.CallAfter(self.window.ThreadFinished, self)
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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:...
|
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...
| |
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...
|
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...
|
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;
|
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;
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |