Hi Folks,

I need to run an infinite loop on a Menu button, like this:

from Tkinter import *

def run_job():
    i = 0
    while 1:
        i = i + 1
        if i > 100:
            break
     .......

root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="Jobs", menu=filemenu)
filemenu.add_command(label="Run", command=run_job)
mainloop()


In fact, the def run_job has more things to do. But, it is an infinite loop in 
essence. It works. However, when the def run_job is running, the menu will be 
hang there. I have no way to stop it. Even if I raise it with Key-Interupt, the 
thing was the same: the infinite loop cannot be stopped nicely. The only way 
was to wait until the Python interpreter notice the problem, and popped out an 
error message, then I can kill the running program.

Can anybody tell me how to handle this? I wish when variable i reached 100, the 
run_job will be end, and the Menu "Run" will be free.

Thanks in advance. 

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to