[New-bugs-announce] [issue14163] tkinter: problems with hello doc example

Terry J. Reedy report at bugs.python.org
Thu Mar 1 01:00:48 CET 2012


New submission from Terry J. Reedy <tjreedy at udel.edu>:

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 *

----------
assignee: docs at python
components: Documentation, Tkinter
messages: 154669
nosy: docs at python, ned.deily, serwy, terry.reedy
priority: normal
severity: normal
status: open
title: tkinter: problems with hello doc example
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14163>
_______________________________________


More information about the New-bugs-announce mailing list