Skip to content

tkinter doc, hello world example - quit button clobbers method #89192

Closed

Description

@lyndondarcy
BPO 45029
Nosy @terryjreedy, @serhiy-storchaka, @miss-islington, @E-Paine
PRs
  • [3.9] bpo-42560: rewrite of Tkinter docs "life preserver" (GH-27842) #27911
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-28.17:54:10.251>
    created_at = <Date 2021-08-27.09:03:24.592>
    labels = ['expert-tkinter', '3.9', 'docs']
    title = 'tkinter doc, hello world example - quit button clobbers method'
    updated_at = <Date 2021-08-28.17:54:10.250>
    user = 'https://bugs.python.org/lyndondarcy'

    bugs.python.org fields:

    activity = <Date 2021-08-28.17:54:10.250>
    actor = 'terry.reedy'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-08-28.17:54:10.251>
    closer = 'terry.reedy'
    components = ['Documentation', 'Tkinter']
    creation = <Date 2021-08-27.09:03:24.592>
    creator = 'lyndon.darcy'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45029
    keywords = ['patch']
    message_count = 5.0
    messages = ['400403', '400404', '400407', '400433', '400487']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'docs@python', 'serhiy.storchaka', 'miss-islington', 'epaine', 'lyndon.darcy']
    pr_nums = ['27911']
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue45029'
    versions = ['Python 3.9']

    Activity

    1. lyndondarcy commented on Aug 27, 2021

      lyndondarcymannequin
      MannequinAuthor

      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.

    2. added
      docs
      3.9 (EOL)
      on Aug 27, 2021
    3. added
      docs
      on Aug 27, 2021
    4. serhiy-storchaka commented on Aug 27, 2021

      @serhiy-storchaka
      Member

      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.
       |  
      ...
    5. lyndondarcy commented on Aug 27, 2021

      lyndondarcymannequin
      MannequinAuthor

      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 <[email protected]>
      wrote:

      Serhiy Storchaka <[email protected]> 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 <[email protected]>
      <https://bugs.python.org/issue45029\>


    6. E-Paine commented on Aug 27, 2021

      E-Painemannequin
      Mannequin

      Thanks for reporting this issue. This was (very) recently fixed in bpo-42560 / 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.

    7. terryjreedy commented on Aug 28, 2021

      @terryjreedy
      Member

      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.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)docstopic-tkinter

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions