Threads and Tkinter GUI ...

Arild Hansen arildh at stud.cs.uit.no
Mon Oct 23 15:43:40 EDT 2000


Grant Edwards wrote:

> In article <39F40343.2978F59B at stud.cs.uit.no>, Arild Hansen wrote:
>
> >what I want: When I start the xclient I first create a thread called
> >"pingServer" which is resonsible for pinging the server at regular
> >intervals. When this thread is started I start the GUI's mainloop.
> >I will then have a GUI running and a thread running in the background
> >pinging the server. If the server is not found, the pingServer thread
> >will update a global variable and a led light will turn red in the GUI.
>
> If I were you, I'd just use the after() method on the top-level window to
> schedule a function to run every 5 seconds.  It's a lot simpler than doing
> the whole thread thing.
>
> I don't seem to have an example handy, but it works something like this
> (warning, I've been doing pyGtk stuff more recently than Tkinter stuff, so I
> may have this not-quite-right, so you should probably find a real example or
> look at the Tk docs):
>
> def doSomething(*args):
>    # insert ping code here
>    win.after(5000, doSomething)
>
> win = Tk()
>
> # set up everything
>
> ...
>
> # start pinging
>
> doSomething()
>
> --
> Grant Edwards                   grante             Yow!  ... Get me a GIN
>                                   at               and TONIC!!...make it
>                                visi.com            HAIR TONIC!!

Thx for your response! I actually found my problem. It seemed that I started my
pingThread that eventually made a "import guimaker" statement. But when
starting the GUI, the guimaker module is used since it is a superclass. So it
seems like the pingThread and the GUI were trying to access this same module at
approximately the same time. Don't know why that shouldn't work though since
the pingThread only imported the guimaker class without accessing any of its
contents (so therefore I could safely remove it and my pingThread wroked just
fine).

Well, I'll look into the "after" thingy anyway since it seems like a more
reasonable approach in my situation. So thanks for your help. If anyone can
tell my why my program didn't work when I had "import guimaker" in my
pingThread, please tell me as I am curious.

Arild Hansen




More information about the Python-list mailing list