Tkinter/IDLE crash
Mike Callahan
mcalla at home.com
Mon Dec 13 20:35:54 EST 1999
> I was making my first foray into Tkinter last night (using Py 1.5.2
> and IDLE with Win 95). Like a good little learner, I typed in the
> simple example from "An introduction to Tkinter", chapter 3:
>
> ---------------------------
> from Tkinter import *
>
> class App:
>
> def __init__(self, master):
>
> frame = Frame(master)
> frame.pack()
>
> self.button = Button(frame, text="QUIT", fg="red",
command=frame.quit)
> self.button.pack(side=LEFT)
>
> 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!"
>
> root = Tk()
>
> app = App(root)
>
> root.mainloop()
> ---------------------------
>
> Press the "Hello" button, and it says hello. Fine and dandy. But press
> the "Quit" button, and *everything* quits. The window, the IDLE session,
> everything! Goodbye python, goodbye IDLE, hello desktop.
>
> Anyone know what's going on here? Something wrong with my installation,
> perhaps? I'm a Unix boy, so I'll be the first to admit that I might have
> stuffed up the Windows setup somehow.
>
I am a newbie also but I found out that calling quit() does not work inside
of IDLE since IDLE is also a Tk application. When you call quit, it REALLY
quits. Use destroy(). Here is a simple script that works inside of IDLE.
from Tkinter import *
root = Tk()
frame = Frame(root)
frame.pack()
button = Button(frame, text='Exit', command=root.destroy)
button.pack()
root.mainloop()
An OOP programmer would shudder, (no classes) but I have used this script as
a starting point.
More information about the Python-list
mailing list