如何在处理时弹出消息 - python
我想知道,在运行程序或函数的时候,怎么弹出消息。我是说,
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)
我想显示一条消息,说明正在计算特征,一旦计算完成,这条消息就应该消失。
不过我不需要有 ok
按钮。我不知道该怎么实现。计算的结果会显示在一个单独的输入框里。欢迎任何建议。
1 个回答
4
看看这个。它会打开一个窗口,里面显示一些文字,当计算完成后,这些文字会变成结果。
>>> 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))