我想知道,如何在处理/执行程序/功能时弹出消息。我的意思是,
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
按钮。我不知道如何实现这一点。这些计算的结果将显示在单独的输入框中。欢迎任何建议。
答案 0 :(得分:2)
看看这个。它打开一个包含文本的窗口,当计算完成时,文本将更改为结果。
>>> 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))