[issue45029] tkinter doc, hello world example - quit button clobbers method

2021-08-27 Thread Lyndon D';Arcy


New submission from Lyndon D'Arcy :

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.

--
assignee: docs@python
components: Documentation, Tkinter
messages: 400403
nosy: docs@python, lyndon.darcy
priority: normal
severity: normal
status: open
title: tkinter doc, hello world example - quit button clobbers method
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue45029>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45029] tkinter doc, hello world example - quit button clobbers method

2021-08-27 Thread Lyndon D';Arcy


Lyndon D'Arcy  added the comment:

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 
wrote:

>
> Serhiy Storchaka  added the comment:
>
> I get different result:
>
> >>> app.quit
> 
> >>> 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 
> <https://bugs.python.org/issue45029>
> ___
>

--

___
Python tracker 
<https://bugs.python.org/issue45029>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com