Skip to content Skip to sidebar Skip to footer

How To Pop Up A Message While Processing - Python

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

Solution 1:

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

Post a Comment for "How To Pop Up A Message While Processing - Python"