Reputation: 862
I want to know, how to pop-up messages while processing/executing a program/function. I mean,
def Select():
path=tkFileDialog.askopenfilename(filetypes=[("Image File",'.jpg')])
im = skimage.io.imread(path, as_grey=True)
im = skimage.img_as_ubyte(im)
im /= 32
g = skimage.feature.greycomatrix(im, [1], [0], levels=8, symmetric=False, normed=True)
cont = skimage.feature.greycoprops(g, 'contrast')[0][0]
cont_list1.append(cont)
ene = skimage.feature.greycoprops(g, 'energy')[0][0]
ene_list1.append(ene)
homo = skimage.feature.greycoprops(g, 'homogeneity')[0][0]
homo_list1.append(homo)
cor = skimage.feature.greycoprops(g, 'correlation')[0][0]
cor_list1.append(cor)
dis = skimage.feature.greycoprops(g, 'dissimilarity')[0][0]
dis_list1.append(dis)
I want to display a message stating Features are being calculated, and once it calculates, the message should disappear.
But I don't need the ok
button.I don't know how to achieve this.The result of these calculations will be displayed in separate Entry box. Any suggestions are welcome.
Upvotes: 3
Views: 6935
Reputation: 14873
Have a look at this. It opens a window with the text and when the computation is done the text is changed to the result.
>>> import time
>>> def processingPleaseWait(text, function):
import Tkinter, time, threading
window = Tkinter.Toplevel() # or tkinter.Tk()
# code before computation starts
label = Tkinter.Label(window, text = text)
label.pack()
done = []
def call():
result = function()
done.append(result)
thread = threading.Thread(target = call)
thread.start() # start parallel computation
while thread.is_alive():
# code while computing
window.update()
time.sleep(0.001)
# code when computation is done
label['text'] = str(done)
>>> processingPleaseWait('waiting 2 seconds...', lambda: time.sleep(2))
Upvotes: 4