[Tutor] Developing GUI-programs using IDLE
Gregor Lingl
glingl@aon.at
Sun, 21 Oct 2001 01:53:59 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0093_01C159D3.40368190
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi folks!
I'd like to develop GUI-programs with Tkinter
using IDLE. (Remark: I'm running Python under
WindowsNT)
Apparently there arise problems from the fact,
that IDLE itself is a Tkinter-program.
Running the following program (taken from life-preserver):
from Tkinter import * =
=
class Application(Frame): =
def say_hi(self): =
print "hi there, everyone!" =
=
def createWidgets(self): =
self.QUIT =3D Button(self) =
=20
self.QUIT["text"] =3D "QUIT" =
=20
self.QUIT["fg"] =3D "red" =
=20
self.QUIT["command"] =3D self.quit # crucial point =
No. 1 =20
=20
self.QUIT.pack({"side": "left"}) =20
=20
self.hi_there =3D Button(self) =
=20
self.hi_there["text"] =3D "Hello", =
=20
self.hi_there["command"] =3D self.say_hi =
=20
=20
self.hi_there.pack({"side": "left"}) =20
=20
=20
def __init__(self, master=3DNone): =
=20
Frame.__init__(self, master) =20
self.pack() =20
self.createWidgets() =20
=20
app =3D Application() =
=20
app.mainloop() # crucial point No. 2 =20
results in:
a) if I press the QUIT-button IDLE collapses as a whole
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)
if I delete (comment out) the last statement:=20
app.mainloop()
a) remains the same
b) (seemingly) works well: window closes,=20
new prompt in IDLE appears
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 would appreciate very much
a) an explanation of this weird behaviour
b) a directive for how to handle mainloop() in the given
circumstances
c) a statement (method-call) that causes the Application
to close and exit properly without killing IDLE
Otherwise developing GUI-programs with IDLE would be rather
uncomfortable.
Gregor Lingl
------=_NextPart_000_0093_01C159D3.40368190
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Courier New" size=3D2>Hi folks!</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>I'd like to develop =
GUI-programs with=20
Tkinter</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>using IDLE. (Remark: I'm =
running Python=20
under</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>WindowsNT)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Apparently there arise problems =
from the=20
fact,</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>that IDLE itself is a=20
Tkinter-program.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Running the following =
program (taken=20
from life-preserver):</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>from Tkinter import=20
* =
&=
nbsp; &n=
bsp; &nb=
sp; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR>class=20
Application(Frame): =
&=
nbsp; &n=
bsp; &nb=
sp; =20
<BR> def=20
say_hi(self): =
&=
nbsp; &n=
bsp; &nb=
sp; =20
<BR> &nb=
sp; =20
print "hi there,=20
everyone!" &nb=
sp; &nbs=
p; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR> def=20
createWidgets(self):  =
; =
&=
nbsp; =20
<BR> &nb=
sp; =20
self.QUIT =3D=20
Button(self) &=
nbsp; &n=
bsp; =20
<BR> &nb=
sp; =20
self.QUIT["text"] =3D=20
"QUIT" &=
nbsp; &n=
bsp; =20
<BR> &nb=
sp; =20
self.QUIT["fg"] =3D=20
"red" &n=
bsp; &nb=
sp; =20
<BR> &nb=
sp; =20
self.QUIT["command"] =3D self.quit # crucial =
point No.=20
1 =
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; <BR>  =
; =20
self.QUIT.pack({"side":=20
"left"})  =
; =
=20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR> &nb=
sp; =20
self.hi_there =3D=20
Button(self) &=
nbsp; &n=
bsp; =20
<BR> &nb=
sp; =20
self.hi_there["text"] =3D=20
"Hello",  =
; =
=20
<BR> &nb=
sp; =20
self.hi_there["command"] =3D=20
self.say_hi &n=
bsp; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR> &nb=
sp; =20
self.hi_there.pack({"side":=20
"left"})  =
; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR> def __init__(self,=20
master=3DNone): &nbs=
p;  =
; =
=20
<BR> &nb=
sp; =20
Frame.__init__(self,=20
master) =
&=
nbsp; =20
<BR> &nb=
sp; =20
self.pack() &n=
bsp; &nb=
sp; &nbs=
p; =20
<BR> &nb=
sp; =20
self.createWidgets()  =
; =
&=
nbsp; =20
<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; =20
<BR>app =3D=20
Application() =
&=
nbsp; &n=
bsp; &nb=
sp; =20
<BR>app.mainloop() # crucial point=20
No. 2 &nb=
sp; =20
<BR></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>results in:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> a) if I press the =
QUIT-button=20
IDLE collapses as a whole</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> b) if I click on =
the=20
window-closing 'x' (right upper corner)</FONT></DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2> the=20
programs window closes, but the REP-loop of IDLE does</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> =
not return,=20
so I have to kill it via the Task-Manager</FONT></DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2> (I=20
don't know how to kill the running program alone)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>if I delete (comment =
out) the last=20
statement: </FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>app.mainloop()</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> a) remains the=20
same</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> b) (seemingly) =
works well:=20
window closes, </FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> =
new prompt=20
in IDLE appears</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>if I try to remedy point =
a) above by=20
replacing self.quit</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>by self.destroy (assuming self =
to be=20
App that is Frame)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>something very strange occurs: =
pressing the=20
QUIT-button results</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>in disappearance of BOTH =
buttons, and the=20
empty Frame-window remains</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>on the screen. Now I also can =
remove the=20
Frame by using 'x'</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> </DIV></FONT>
<DIV><FONT face=3D"Courier New" size=3D2>I would appreciate very =
much</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> a) an explanation of this =
weird=20
behaviour</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> b) a directive for how to =
handle=20
mainloop() in the given</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> =20
circumstances</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> c) a statement =
(method-call) that=20
causes the Application</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2> to close and =
exit=20
properly without killing IDLE</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Otherwise developing =
GUI-programs with IDLE=20
would be rather</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>uncomfortable.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Gregor Lingl</FONT></DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0093_01C159D3.40368190--