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.

classification
Title: tkinter doc, hello world example - quit button clobbers method
Type: Stage: resolved
Components: Documentation, Tkinter Versions: Python 3.9
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, epaine, lyndon.darcy, miss-islington, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2021-08-27 09:03 by lyndon.darcy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27911 miss-islington, 2021-08-28 17:48
Messages (5)
msg400403 - (view) Author: Lyndon D'Arcy (lyndon.darcy) Date: 2021-08-27 09:03
Below is the example as it is.  Currently self.quit clobbers a built-in method of the same name.  I would suggest renaming self.quit to self.quit_button or similar.

-------------------------------------------------------

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()

-----------------------------------------------------------

>>> help(app.quit)
Help on method quit in module tkinter:

quit() method of __main__.Application instance
    Quit the Tcl interpreter. All widgets will be destroyed.
msg400404 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-08-27 09:38
I get different result:

>>> app.quit
<tkinter.Button object .!application.!button2>
>>> help(app.quit)
Help on Button in module tkinter object:

class Button(Widget)
 |  Button(master=None, cnf={}, **kw)
 |  
 |  Button widget.
 |  
...
msg400407 - (view) Author: Lyndon D'Arcy (lyndon.darcy) Date: 2021-08-27 10:09
Apologies, my original post was unclear.

The help(app.quit) which I posted is what we should get when the method
isn't clobbered.

What Serhiy has posted is what you get after running the example as-is.  It
shows that after running the example self.quit refers to a button object
instead of the quit method.

On Fri, 27 Aug 2021 at 7:38 pm, Serhiy Storchaka <report@bugs.python.org>
wrote:

>
> Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:
>
> I get different result:
>
> >>> app.quit
> <tkinter.Button object .!application.!button2>
> >>> help(app.quit)
> Help on Button in module tkinter object:
>
> class Button(Widget)
>  |  Button(master=None, cnf={}, **kw)
>  |
>  |  Button widget.
>  |
> ...
>
> ----------
> nosy: +serhiy.storchaka
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue45029>
> _______________________________________
>
msg400433 - (view) Author: E. Paine (epaine) * Date: 2021-08-27 17:01
Thanks for reporting this issue. This was (very) recently fixed in issue42560 / PR27842. These changes include a new hello world example and can be seen in the 3.10 / 3.11 docs (https://docs.python.org/3.10/library/tkinter.html#a-hello-world-program). This change was backported to 3.9 docs, but the build bots have yet to rebuild the version hosted on docs.python.org.
msg400487 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-08-28 17:54
For whatever reason, the 3.9 backport, PR-27911, was closed.  In any case, we will not edit the code we have replaced.

Lyndon, when responding by email, please delete the old text as it is redundant and noisy when your email is added to the web page.
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89192
2021-08-28 17:54:10terry.reedysetstatus: open -> closed

nosy: + terry.reedy
messages: + msg400487

resolution: out of date
stage: patch review -> resolved
2021-08-28 17:48:35miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request26458
stage: patch review
2021-08-27 17:01:33epainesetnosy: + epaine
messages: + msg400433
2021-08-27 10:09:19lyndon.darcysetmessages: + msg400407
2021-08-27 09:38:35serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg400404
2021-08-27 09:03:24lyndon.darcycreate