Tkinter(newbie) Inside Pythonwin

Gordon McLeod Gordon.McLeod at wolfson.co.uk
Thu Sep 28 08:02:01 EDT 2000


root.destroy works fine Kragen. Thanks for your help.

Gordon McLeod,

Kragen Sitaker wrote:

> In article <39D09D53.C036926E at wolfson.co.uk>,
> Gordon McLeod  <Gordon.McLeod at wolfson.co.uk> wrote:
> >I'm having problems running a simple example from Fredrik Lundh's An
> >Introduction to Tkinter book in Pythonwin.
> >
> >http://www.pythonware.com/library/tkinter/introduction/hello-again.htm
> >
> >When I run from windows explorer it works fine, but from pythonwin
> >(1.5.2) the QUIT button doesn't close the window. The The tk window is
> >left on the screen and running again creates more tk windows. The window
> >'X' box closes the window in both, and the hello button works fine in
> >both.
>
> Calling frame.quit terminates the main loop, not the program.  Running
> non-interactively, terminating the main loop terminates the program;
> running interactively, it just returns you to the Python prompt.
>
> At least, that's what's happening on my Linux box :)
>
> >Is there a missing destroy call or something?
>
> Changing frame.quit to root.destroy seems to make it do what you expect
> it to do.
>
> >I reproduce the example below:
> >
> > . . .
> >       self.hi_there = Button(frame, text="Hello", command=self.say_hi)
> >       self.hi_there.pack(side=LEFT)
> >
> >   def say_hi(self):
> >       print "hi there, everyone!"
>
> This is a perfect example of why generalized lambda would be a useful
> thing.  There's no need to put say_hi in a separate function; callbacks
> from GUI objects can usually more conveniently be simple anonymous
> blocks of code than named functions.  I'd like to be able to say
>
> self.hi_there = Button(frame, text="Hello",
>                        command=lambda: print "hi there, everyone!")
>
> instead.  Which is what I do in Tcl:
>
> frame .frame
> pack .frame
> button .frame.button -text Hello -command {puts "hi there, everyone!"}
> pack .frame.button
>
> and Perl, although bizarrely I don't have Perl's Tk interface installed
> at the moment, so I can't confidently post syntax, but it's something
> like -command => sub { print "hi there, everyone!\n" }.
> --
> <kragen at pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
> Perilous to all of us are the devices of an art deeper than we ourselves
> possess.
>                 -- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]




More information about the Python-list mailing list