473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Appropriate way to quit Tkinter

I've just started playing with Python. Installed 2.5 on Windows XP
system. I'm working through some of the examples in Programming Python
3ed by Mark Lutz. Given the following example when the Quit All button
action is assigned to root.quit the windows aren't dismissed or
destroyed. The application appears to terminate, but the windows
remain. When the action is assigned to root.destroy, the windows are
closed. Questions:
1) Which way is preferred / correct?
2) Is something wrong with 2.5? (I haven't tried older versions of
python)
3) Is there something wrong with my installation?
################################################## ###########################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app;
top-level
# windows have title, icon, iconify/deiconify and protocol for wm
events;
# there always is an app root window, whether by default or created as
an
# explicit Tk() object; all top-level windows are containers, but never

# packed/gridded; Toplevel is like frame, but new window, and can have
menu;
################################################## ###########################

from Tkinter import *
root = Tk() # explicit root

trees = [('The Larch!', 'light blue'),
('The Pine!', 'light green'),
('The Giant Redwood!', 'red')]

for (tree, color) in trees:
win = Toplevel(root)
# new window
win.title('Sing...')
# set border
win.protocol('WM_DELETE_WINDOW', lambda:0) # ignore close
win.iconbitmap('py-blue-trans-out.ico') # not red Tk

msg = Button(win, text=tree, command=win.destroy) # kills one win
msg.pack(expand=YES, fill=BOTH)
msg.config(padx=10, pady=10, bd=10, relief=RAISED)
msg.config(bg='black', fg=color, font=('times', 30, 'bold italic'))

root.title('Lumberjack demo')
Label(root, text='Main window', width=30).pack()
#Button(root, text='Quit All', command=root.quit).pack() # kills
all app
Button(root, text='Quit All', command=root.destroy).pack() # kills all
app
root.mainloop()

Oct 12 '06 #1
5 13289
mzdude wrote:
I've just started playing with Python. Installed 2.5 on Windows XP
system. I'm working through some of the examples in Programming Python
3ed by Mark Lutz. Given the following example when the Quit All button
action is assigned to root.quit the windows aren't dismissed or
destroyed. The application appears to terminate, but the windows
remain. When the action is assigned to root.destroy, the windows are
closed. Questions:
1) Which way is preferred / correct?
quit() causes the mainloop() call to return. if calling mainloop() is
the last thing you do in your program, the program terminates.

destroy() destroys the given window. if that's the last window, the
mainloop() is terminated as well.
2) Is something wrong with 2.5? (I haven't tried older versions of
python)
not that I can see.
3) Is there something wrong with my installation?
works for me. are you perhaps running this under some kind of IDE that
keeps the process running even after the program has terminated?

</F>

Oct 12 '06 #2

Fredrik Lundh wrote:
[snip]
works for me. are you perhaps running this under some kind of IDE that
keeps the process running even after the program has terminated?
It works the same way if I run from IDLE or from the DOS command prompt.

Oct 13 '06 #3
On 2006-10-13, mzdude <js****@cox.netwrote:
>
Fredrik Lundh wrote:
[snip]
>works for me. are you perhaps running this under some kind of
IDE that keeps the process running even after the program has
terminated?

It works the same way if I run from IDLE or from the DOS
command prompt.
I had some fun trying to run Tkinter from from the Python
embedded in Vim. My advice: Do not do that.

--
Neil Cerutti
The majority of time, it seems to be one thing or the other.
--Ron Mercer
Oct 13 '06 #4
mzdude wrote:
>works for me. are you perhaps running this under some kind of IDE that
keeps the process running even after the program has terminated?
It works the same way if I run from IDLE or from the DOS command prompt.
I find very hard to believe that a Python interpreter run from the DOS
command prompt wouldn't terminate when it reaches the end of the main
program.

what Python distribution are you using?

</F>

Oct 13 '06 #5

Fredrik Lundh wrote:
mzdude wrote:
works for me. are you perhaps running this under some kind of IDE that
keeps the process running even after the program has terminated?
It works the same way if I run from IDLE or from the DOS command prompt.

I find very hard to believe that a Python interpreter run from the DOS
command prompt wouldn't terminate when it reaches the end of the main
program.

what Python distribution are you using?

</F>
Not sure I understand the question. I downloaded python-2.5.msi from
python.org/download.
>From the IDLE
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

Oct 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5958
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
3
3876
by: Jane Austine | last post by:
>Jane Austine wrote: >>>>from Tkinter import * >>>>>r=Tk() >>>>>b=Button(r,text='Quit',command=r.quit) >>>>>b.pack() >>>>>r.mainloop() >> >> >> And when I press the "Quit" button the mainloop...
7
11882
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
1
2952
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
3565
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
0
1338
by: Brandon | last post by:
Hi All, I'm attempting to develop a Tcl/Tk application on the mac using python and Tkinter. The one problem I'm having is adding basic keyboard support to my application, specifically binding...
3
2817
by: al pacino | last post by:
i have a weired problem with button widget in Tkinter the callback function(Tk.quit()) for button widget is not working! when i 'press' the button the GUI hangs. code for displaying a 'button...
3
3592
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
8
3264
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.