如何在处理时弹出消息 - python [英] How to pop up a message while processing - python

查看:25
本文介绍了如何在处理时弹出消息 - python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如何在处理/执行程序/函数时弹出消息.我的意思是,

def Select():path=tkFileDialog.askopenfilename(filetypes=[("Image File",'.jpg')])im = skimage.io.imread(path, as_grey=True)im = skimage.img_as_ubyte(im)我/= 32g = skimage.feature.greycomatrix(im, [1], [0], levels=8, symmetric=False, normed=True)cont = skimage.feature.greycoprops(g, '对比')[0][0]cont_list1.append(cont)ene = skimage.feature.greycoprops(g, '能量')[0][0]ene_list1.append(ene)homo = skimage.feature.greycoprops(g, '同质性')[0][0]homo_list1.append(homo)cor = skimage.feature.greycoprops(g, '相关性')[0][0]cor_list1.append(cor)dis = skimage.feature.greycoprops(g, '不同')[0][0]dis_list1.append(dis)

我想显示一条消息,说明正在计算特征,一旦计算完成,该消息就会消失.

但我不需要ok按钮.我不知道如何实现.这些计算的结果将显示在单独的输入框中.欢迎提出任何建议.

解决方案

看看这个.它打开一个带有文本的窗口,当计算完成时,文本将更改为结果.

<预><代码>>>>导入时间>>>def processingPleaseWait(text, function):导入 Tkinter、时间、线程window = Tkinter.Toplevel() # 或 tkinter.Tk()# 计算开始前的代码label = Tkinter.Label(window, text = text)标签.pack()完成 = []定义调用():结果 = 函数()done.append(结果)线程 = threading.Thread(目标 = 调用)thread.start() # 开始并行计算而 thread.is_alive():# 计算时的代码窗口.更新()时间.睡眠(0.001)# 计算完成时的代码label['text'] = str(done)>>>processingPleaseWait('等待 2 秒...', lambda: time.sleep(2))

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.

解决方案

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))

这篇关于如何在处理时弹出消息 - python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆