[Tutor] (no subject)
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 11 Apr 2001 16:58:05 -0700 (PDT)
On Wed, 11 Apr 2001, Glen Bunting wrote:
> Your version works perfectly except for one thing, when I click on the quit
> button, nothing happens. I will continue to use the program the way you
> wrote it, but I have a few questions about the way I was trying to write it.
Hmmm... strange! What might be happening is that the updating action is
taking a long time. At the moment, the program is written to only be able
to do one task at a time. The call to:
urllib.urlretrieve('http://www.esynch.com/mw_test.dat', 'test')
takes a heck of a lot of time, precisely because the file is HUGE, even
with a broadband connection. *grin*. That's probably why the GUI isn't
as responsive as it should be: it's only doing one thing at a time. Try
your program on a less stressful URL, and see if this is the case.
> 2: As long as Tkinter.mainloop() remains in the while loop, the while
> loop does not continue until after I quit Tkinter. Once I do that the
> loop continues. If I take Tkinter.mainloop out of the while loop, the
> loop continues like it should , but the gui never pops up.
The role of the mainloop() call is to pass control of your program off to
Tkinter --- after caling mainloop(), it's all "hands-off". I believe this
is called "event-driven programming", because anything that happens
afterwards is a response to what the user does with the GUI.
The control flow of our GUI programs, then, looks like:
start ----> initialize stuff ---> initialize GUI -+
|
+------------------<-------------------+
|
+----> do GUI stuff ---+---> turn off GUI ---> done!
| |
+----------<-----------+
handle an "event"
The "do GUI stuff" loopiness is what the mainloop() is doing: it keeps on
looping until we can't look at any more "events", and then we finish the
program. It's a different style of programming than what you might be
used to.
> The next thing I might be interested in doing is to graph the results. Is
> that the next logical step, or would that be a little to advanced for a
> newbie?
Graphing sounds like a great idea. You'll want to play around with the
Canvas widget. If you want, I can take a look at Grayson's "Python and
Tkinter Programming" to review how Canvases work.
There's supposedly a really good module that works with Tkinter to make
really nice widgets. It's called Python Mega Widgets, and I think it has
a graphing widget that might be useful. If you're interested, take a
look:
http://pmw.sourceforge.net
Lots of good stuff.
Anyway, good luck to you.