[Tutor] Developing GUI-programs using IDLE

Glen Wheeler wheelege@tsn.cc
Sun, 21 Oct 2001 12:24:47 +1000


  In the absence of any replies, I'll try my hand at helping you out.  I
doubt my ability though, so if something I say seems a little odd, then it's
probably wrong.  Here goes...

> Apparently there arise problems from the fact,
> that IDLE itself is a Tkinter-program.

  That's what most of the things your encountering are symptoms of.  I found
the best way to develop tkinter programs is to create a batch file (*.bat)
which you then throw on your shortcut bit in the start bar or desktop, then
double click on that to run a predetermined python script.  That means
running through a dos box is actually pretty quick.
  And most important of all, it works :)
  I was using the PythonWin environment from Activestate (get it from the
downloads page at python.org) to develop tkinter programs, because it does
not exhibit these problems.  However, upon trying your example inside it
there was different but no less irritating errors.  I really don't know why
this would be.

> Running the following program (taken from life-preserver):
>
> <...>
>
> results in:
>   a) if I press the QUIT-button IDLE collapses as a whole

  Here is where I'm not sure.  I think that when tkinter gets a call from
quit it recursively searches and kills all mainloop()'s.  I think.

>   b) if I click on the window-closing 'x' (right upper corner)
>      the programs window closes, but the REP-loop of IDLE does
>      not return, so I have to kill it via the Task-Manager
>      (I don't know how to kill the running program alone)

  I think (so confident!) this is because IDLE's mainloop gets confused with
the program's mainloop and funny things happen.  Somewhere I read that
tcl/tk can only ever have one mainloop going inside any one program, and
when you start up another inside the script then that takes over from IDLE's
mainloop, so that when you stop it IDLE stops too.  But I am probably wrong
:)

> if I delete (comment out) the last statement:
> app.mainloop()
>    a) remains the same

  Again, I think that is deliberate.

>    b) (seemingly) works well: window closes,
>       new prompt in IDLE appears

  That is the recommended way to test tkinter programs through IDLE, and
sorta works but really...I'd use the batch file.

> if I try to remedy point a) above by replacing self.quit
> by self.destroy (assuming self to be App that is Frame)
> something very strange occurs: pressing the QUIT-button results
> in disappearance of BOTH buttons, and the empty Frame-window remains
> on the screen. Now I also can remove the Frame by using 'x'

  I've got no idea about this one.  I had a look through the code and
self.destroy should kill the frame....which it does do in the PythonWin
environment, but leaves the two buttons and the window.  One thing I noticed
is that there is no root = Tk() call inside the script, mayhap that could
have somethin to do with it?

> I would appreciate very much
>  a) an explanation of this weird behaviour

  I tried :)

>  b) a directive for how to handle mainloop() in the given
>     circumstances

  I'd use the batch method, if you need help on that then just repost.

>  c) a statement (method-call) that causes the Application
>     to close and exit properly without killing IDLE

  Again...I don't know except for leaving out the mainloop() call, and even
that has it's problems.  I'd go for the batch deal.

> Otherwise developing GUI-programs with IDLE would be rather
> uncomfortable.

  It is :)

  HTH,
  Glen