【问题标题】:How to pop up a message while processing - python如何在处理时弹出消息 - python
【发布时间】:2014-04-22 09:11:49
【问题描述】:

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

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 按钮。我不知道如何实现。这些计算的结果将显示在单独的输入框中。欢迎提出任何建议。

【问题讨论】:

  • effbot.org/tkinterbook/tkinter-standard-dialogs.htm effbot.org/tkinterbook/toplevel.htm 用于您可以自定义的弹出窗口(即,没有按钮,只有一条消息,会自动销毁)。
  • 您想了解更多关于“创建消息框/窗口”或“如何在计算某些东西时保持 GUI 交互?”的信息。添加速度非常快,以至于它可能不可见。
  • @User 添加是一个例子,但我想知道“如何在计算某些东西时保持 GUI 交互?”
  • 然后我建议阅读此内容:stackoverflow.com/questions/21532523/… 并报告,如果需要进行调整。
  • @User 这不是我的意思,你观察到谷歌的处理事情了吗?就像我想显示这样的消息_计算总和_按顺序排列然后结果应该显示。我希望你能得到我的看法!

标签: python tkinter


【解决方案1】:

看看这个。它会打开一个带有文本的窗口,计算完成后,文本会更改为结果。

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

【讨论】:

    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多