Detect events positively
Xiao-Qin Xia
xx758 at cam.ac.uk
Fri Jun 7 11:52:52 EDT 2002
Hello,
The following code display two button:
from Tkinter import *
def Calculate(event = None):
while 1:
pass
def Exit(event = None):
import sys
sys.exit(0)
root = Tk()
btn_cal = Button(root, text="calculate", command = Calculate)
btn_cal.pack()
btn_exit = Button(root, text="exit", command = Exit)
btn_exit.pack()
root.mainloop()
if clicked the "calculate" button, the program will fall in a loop that
will never end. So program will not response to clicking to the "exit"
button, so it cannot be terminated normally. If we don't use multithread,
can we add some code in the loop of the function Calculate to let it exit
the loop after the user clicks the "exit" button or press a "Esc" key?
Many thanks from,
Xiao-Qin Xia
More information about the Python-list
mailing list