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.

varsha_holla
  • 852
  • 7
  • 23
  • 41
  • http://effbot.org/tkinterbook/tkinter-standard-dialogs.htm <-- for a message box with buttons. Or http://effbot.org/tkinterbook/toplevel.htm for a pop-up window that you can customize (ie, no buttons, just a message, is destroyed automatically). – atlasologist Apr 22 '14 at 11:07
  • Do you want to know more about "creating message boxes/windows" or on "how to keep the GUI interactive while computing something?". The addition is so fast that it may not be visible. – User Apr 22 '14 at 12:43
  • @User addition was an example, but I want to know "how to keep the GUI interactive while computing something?" – varsha_holla Apr 22 '14 at 15:21
  • Then I recomment reading this: http://stackoverflow.com/questions/21532523/tkinter-loop-and-serial-write and reporting back, if it adjustments need to be made. – User Apr 22 '14 at 19:48
  • @User This is not what i meant, have you observed the processing thing in google? just like that I want to display the message like _ computing the sum_ _arranging in order_ then the result should display. I hope you got my view! – varsha_holla Apr 23 '14 at 05:16
  • If it is in google, could you provide a link or a picture? I still understand it as a combination of atlasologist's and my link suggestions. Could you also add the code that does not work? – User Apr 23 '14 at 07:50

1 Answers1

3

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))
User
  • 14,131
  • 2
  • 40
  • 59