Detect events positively
jepler at unpythonic.net
Fri Jun 7 21:28:57 CEST 2002
If you don't want to use threads, just call the "update" method from
time to time to let Tk handle events. Of course, make sure "Calculate"
can't be invoked recursively or you're in for trouble.
On Fri, Jun 07, 2002 at 04:52:52PM +0100, Xiao-Qin Xia wrote:
> The following code display two button:
> from Tkinter import *
> def Calculate(event = None):
> while 1:
root.update() # let tk handle events
> def Exit(event = None):
> import sys
> root = Tk()
> btn_cal = Button(root, text="calculate", command = Calculate)
> btn_exit = Button(root, text="exit", command = Exit)
> 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