This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients docs@python, ned.deily, roger.serwy, terry.reedy
Date 2012-03-01.00:00:46
SpamBayes Score 2.8310687e-15
Marked as misclassified No
Message-id <1330560048.21.0.5556738264.issue14163@psf.upfronthosting.co.za>
In-reply-to
Content
After an intro, the tkinter docs start with a traditional 'Hello World'.
http://docs.python.org/py3k/library/tkinter.html#a-simple-hello-world-program

Problem 1. The example ends with 
root.destroy
John Salerno, today, on python-list thread "Is it necessary to call Tk() when writing a GUI app with Tkinter?", reported the following, which I verified. On Windows, at least, closing the unlabelled Tk window by clicking the normal [X} close button on the frame causes

_tkinter.TclError: can't invoke "destroy" command:  application has been destroyed

This does not happen if one instead clicks the QUIT button inside the frame (as that does not destroy the app).

Question 1a. Does the example work the same with current tcl/tk on *nix and mac?

I assume it should, but I do not know if the example was buggy from the beginning or if something changes. In any case, I do not want to commit a solution that is not tested on more than my Win7.

Question 1b. How do we most simply fix this part of the example?

In '''self.QUIT["command"] = self.quit''', I changed 'quit' to 'destroy' and the result is to destroy the widgets but leave the outer frame and continue the mainloop.

I tried another solution based on adding
        self.protocol("WM_DELETE_WINDOW", self.onDestroyWindow)
to __init__(), but while this worked for Rick Johnson's class App(tk.Tk) example in his response to Salerno, it does not work for this class Application(Frame) example as the latter has no .protocol attribute.
---

Problem 2. A 'Hello World' example should say 'Hello World' instead of just 'hello'. So I make the trivial edit and tk add braces and displays '{Hello World}'. What??? Adding '\n' does not trigger brace addition, so  "Hello_World\n(click_me)" works as expected.

Queston 2. How does one put a space in a button label with triggering addition of braces, or is this impossible?
---

Problem and Solution 3. The example currently puts a loud capital red QUIT button first, and the quiet lowercase blass hello button second. This is backwards in both placement and emphasis. Putting the expanded hello buttom on top and QUIT under looks better to me.
---

Problem 4 (in the intro, before the example): There is a lot that could be changed or added to the doc, but I think revising 

to use Tkinter all you need is a simple import statement:
import tkinter
Or, more often:
from tkinter import *

(3.x version) to add what I think is the best option, 'import tkinter as tk', as at least equal to the '*' option, should be done soon. I am thinking of something like

to use Tkinter, use one of these import statements:
import tkinter
import tkinter as tk
from tkinter import *
History
Date User Action Args
2012-03-01 00:00:48terry.reedysetrecipients: + terry.reedy, ned.deily, roger.serwy, docs@python
2012-03-01 00:00:48terry.reedysetmessageid: <1330560048.21.0.5556738264.issue14163@psf.upfronthosting.co.za>
2012-03-01 00:00:47terry.reedylinkissue14163 messages
2012-03-01 00:00:46terry.reedycreate