tkinter - tk window remains

Dubois, Jeff Jeff.Dubois at westgroup.com
Fri Nov 15 14:56:56 EST 2002


  Hi Chad,
  The code you suggested did solve the persistent tk window problem.
  Thanks!
  Jeff


-----Original Message-----
From: Chad Netzer [mailto:cnetzer at mail.arc.nasa.gov]
Sent: Thursday, November 14, 2002 4:51 PM
To: Dubois, Jeff; python-list at python.org
Subject: Re: tkinter - tk window remains


On Thursday 14 November 2002 13:29, Dubois, Jeff wrote:
>   I am using Tkinter to bring up a ScrolledText window.
>   However, when the user closes the window by clicking on the X button in
> the upper right of the ScrolledText window the "tk" window remains. 

On my linux machine, your code never pops open a window (since you withdraw 
it), before mainloop().  If I comment that out, it works like you expect 
(closing the window exits the program).  And judging from the code, that is 
to be expected (since you use the rootWindow as the parent of your widget)

I expect that on Windows, the rootWindow is not really the Tk() root window 
(Do you get an extra, blank window if you don't withdraw it?  I assume
that's 
what you mean by the tk window).  Obviously there are platform differences
in 
the behavior of Tk.

I suggest you solve it like this:


from Tkinter import *
from ScrolledText import ScrolledText
import sys

bogusrootWin = Tk()
bogusrootWin.withdraw()
rootWin = Toplevel( master=bogusrootWin )
st = ScrolledText(master=rootWin)
st.pack(side=TOP, expand=1, fill=BOTH)
st.insert(END, "\n\n\n\n       THIS IS MAIN WINDOW!\n")
rootWin.protocol( "WM_DELETE_WINDOW", sys.exit )
rootWin.mainloop()


ie. You explicitly create a Toplevel window to use for your application, and

then using the wm_protocol() method on a Toplevel, you can ask the window 
manager to run sys.exit (or whatever you prefer) when the window is killed.

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list