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 2769
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.
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |