Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21056
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'elif': 0.04; 'none:': 0.07; 'received:verizon.net': 0.07; 'subject:when': 0.07; 'terry': 0.07; 'python': 0.08; '__name__': 0.09; 'attribute.': 0.09; 'presume': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'error:': 0.10; 'am,': 0.12; 'def': 0.13; "'__main__':": 0.16; 'beginning.': 0.16; 'false:': 0.16; 'msg,': 0.16; 'reedy': 0.16; 'subject:() ': 0.16; 'subject:GUI': 0.16; 'subject:app': 0.16; 'subject:writing': 0.16; 'tk()': 0.16; 'this:': 0.16; 'url:bugs': 0.17; 'wrote:': 0.18; 'example.': 0.18; 'written': 0.19; 'jan': 0.19; '(most': 0.21; 'tracker': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'changed': 0.23; '(on': 0.23; 'traceback': 0.24; 'fix': 0.25; 'import': 0.27; 'tried': 0.27; 'effect': 0.28; 'skip:" 30': 0.28; 'explicitly': 0.29; 'class': 0.29; 'example': 0.29; "skip:' 10": 0.29; 'print': 0.29; 'pm,': 0.29; 'closing': 0.30; '3.x': 0.30; 'implicitly': 0.30; 'invoke': 0.30; 'outer': 0.30; 'changes': 0.30; 'subject:?': 0.31; 'app': 0.31; 'does': 0.32; "can't": 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'too': 0.33; 'it?': 0.33; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'doc': 0.34; 'last):': 0.34; 'root': 0.34; 'to:addr:python-list': 0.35; 'however,': 0.35; 'window': 0.35; 'url:python': 0.35; 'beginning': 0.36; 'received:org': 0.36; 'issue': 0.37; 'example,': 0.37; 'but': 0.37; 'entry': 0.37; 'subject:with': 0.37; 'skip:_ 10': 0.38; 'menu': 0.38; 'should': 0.38; 'skip:o 20': 0.38; 'unlike': 0.39; 'url:org': 0.39; 'johnson': 0.39; 'application': 0.40; 'user': 0.40; 'to:addr:python.org': 0.40; 'john': 0.61; 'your': 0.61; 'opened': 0.64; 'clicking': 0.80; 'subject:necessary': 0.84; 'windows)': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? |
| Date | Wed, 29 Feb 2012 19:17:09 -0500 |
| References | <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-74-109-121-73.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| In-Reply-To | <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.306.1330561055.3037.python-list@python.org> (permalink) |
| Lines | 72 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330561055 news.xs4all.nl 6851 [2001:888:2000:d::a6]:43632 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:21056 |
Show key headers only | View raw
On 2/29/2012 9:24 AM, Rick Johnson wrote:
> On Feb 28, 11:06 pm, John Salerno<johnj...@gmail.com> wrote:
>> However, in the Python documentation, I see this:
>>
>> root = Tk()
>> app = Application(master=root)
>> app.mainloop()
>> root.destroy()
>> I tried the above and I got the following error:
>>
>> Traceback (most recent call last):
>> File "C:\Users\John\Desktop\gui.py", line 12, in<module>
>> root.destroy()
>> File "C:\Python32\lib\tkinter\__init__.py", line 1714, in destroy
>> self.tk.call('destroy', self._w)
>> _tkinter.TclError: can't invoke "destroy" command: application has been destroyed
>>
>> So apparently closing the window with the X button (on Windows)
>> implicitly calls the destroy() method of the root frame.
>> If that's the case, why does the documentation explicitly call it?
I do not know if tk has changed since the example was written or if it
was buggy from the beginning. I opened an issue to fix it.
http://bugs.python.org/issue14163
> Most applications will have both: user destroying, and program
> destroying.
> from tkMessageBox import askyesnocancel
from tkinter.messagebox in 3.x
> class App(tk.Tk):
> def __init__(self):
> tk.Tk.__init__(self)
> self.title('Close Me -->')
> self.protocol("WM_DELETE_WINDOW", self.onDestroyWindow)
>
> def onDestroyWindow(self):
> title = 'Confirm App Exit'
> msg = 'Save changes before exiting?'
> result = askyesnocancel(title, msg, default='cancel')
> if result is None:
> return
> elif result is True:
> print 'saving changes'
> elif result is False:
> print 'dont save changes'
> self.destroy()
>
> if __name__ == '__main__':
> app = App()
> app.mainloop()
This works as adjusted for 3.x. I presume that a quit button or menu
entry should also call onDestroyWindow so the effect is the same as
clicking the outer [X] button.
I tried the same approach to fix the doc example, but unlike your class
App(Tk), class App(Frame) does not a .protocol attribute. See the
tracker issue for all my comments on the example.
I considered removing both the quit button and 'root.destroy' to get a
beginning example that works properly, but as you said, having both is
common so I would like both if the solution is not too esoteric.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-28 21:06 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-29 06:24 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Terry Reedy <tjreedy@udel.edu> - 2012-02-29 19:17 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-29 19:22 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Terry Reedy <tjreedy@udel.edu> - 2012-03-01 00:24 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 18:49 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 19:02 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Terry Reedy <tjreedy@udel.edu> - 2012-03-01 22:43 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Terry Reedy <tjreedy@udel.edu> - 2012-03-02 15:19 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Mel Wilson <mwilson@the-wire.com> - 2012-03-02 15:52 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? "Russell E. Owen" <rowen@uw.edu> - 2012-03-05 11:45 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 21:40 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 18:53 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Mark Roseman <mark@markroseman.com> - 2012-03-02 10:57 -0700
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-03-02 10:53 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 20:41 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Terry Reedy <tjreedy@udel.edu> - 2012-03-01 00:40 -0500
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 21:45 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 22:14 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 18:55 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 22:14 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 21:45 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 22:41 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 22:41 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-01 07:38 +0000
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-02-29 23:58 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 18:35 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-03-01 19:15 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-01 19:19 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-03-01 21:22 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? John Salerno <johnjsal@gmail.com> - 2012-03-02 14:16 -0800
Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-03 20:27 -0800
csiph-web