Tkinter - how to catch button clicks when app is busy?

Thomas Lane tom at parlant.com
Tue Mar 14 17:55:25 EST 2000


It looks like a solution to my problem is to change countloop to:

    def countloop(self):
        if self.stopped == 0:
            # continue the counter loop until the stopped flag is set
            self.count.set( self.count.get() + 1 )  # increment counter
            self.app.update_idletasks()             # update the screen
            self.app.after(250,self.countloop)      # set up another iteration

What if my function is doing something that takes a significant amount of time
(my real-world app does) and I want to be able to interrupt it? For example,
what if I'm downloading a file from a web server and I want to be able to cancel
before it's finished (like Netscape)? This example doesn't seem to work for that
situation. Any hints to get me started in the right direction?

Here's what I really want to do:

    SomeTask():
        DoSomeStuff()
        if stopped:
            return
        DoSomeMoreStuff()
        if stopped:
            return
        DoSomeLastStuff()
        if stopped:
            return

I can deal with handling events as they get queued up, but the problem is that
the Tkinter widgets don't respond at all to button clicks while my program is
doing something else. Other GUI kits that I've used (VB, VXRexx) respond to
button clicks by queueing events. Of course, nothing happens until my app gets
around to handling the events, but I can deal with that.

-Tom



More information about the Python-list mailing list