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: Fix tkinter examples to be PEP8 compliant
Type: enhancement Stage: resolved
Components: Documentation, Tkinter Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: John Hagen, SilentGhost, berker.peksag, docs@python, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2016-07-05 13:20 by John Hagen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Fix-tkinter-docs-PEP8.diff John Hagen, 2016-07-06 19:57 review
Messages (12)
msg269820 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-05 13:20
Patch fixes tkinter examples to be PEP8 compliant.
msg269821 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-07-05 13:24
This patch is going to be rejected, camelCase is standard convention in tkinter and logging modules and that's why it is used in documentation as well.
msg269822 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-07-05 13:41
Thanks for the patch. If you want to improve the examples in tkinter documentation, I'd suggest to update Class.__init__(self, ...) to super().__init__(...). There is no old-style classes in Python 3 anymore so those examples could be updated safely.

Also, please read https://docs.python.org/devguide/patch.html. Sending a patch from a Git checkout will only make the review process harder (and I will personally ignore them in the future).
msg269844 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-05 17:49
@Berker, sorry for the incorrect diff format, still new to CPython (and Mercurial) workflow.  I've attached the diff in a new format.

@SilentGhost I see what you mean that camelCase is used often in tkinter (though many of the examples use lower_camel_case, so it seems like at least it's not consistent currently).

The minor issue I was trying to fix with this patch is that I was showing a programmer completely new to Python the tkinter example and when he pasted it into PyCharm it had some PEP8 warnings, so I was hoping to improve that experience slightly for others in the future.  Some of the changes were newlines for PEP8, would those be accepted?  I'm not strongly inclined either way, so if the core team thinks it should not be changed, I'm happy with that.
msg269845 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-07-05 19:46
Except for replacing '' with ""*, I am strongly for this patch. To me, caMelcaSe is ugLy, and should not be encouraged.  I disagree that camelCase is standard convention, at least not currently.  Tkinter itself does not use it.  It does not even use TitleCase much.

As near as I could find, neither http://effbot.org/tkinterbook/tkinter-index.htm nor http://www.tkdocs.com/tutorial/index.html introduce camelCase identifiers.  For instance, http://effbot.org/tkinterbook/tkinter-hello-again.htm, instead of hiThere and sayHi, has

        self.hi_there = Button(frame, text="Hello", command=self.say_hi)
     def say_hi(self):
 
* PEP 8 says "In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this." My personal convention is 'word', which occurs a lot in tkinter code, and 'multi-word phrase or sentence", which is much rarer.  Why the change in the patch.
msg269850 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-05 20:13
@Terry The reason for changing the quotes was for consistency, since everywhere else on that page used double quotes. That being said, I don't have a strong preference and will happily revert it if that is the consensus. I'm +0 on the change.

I personally use single quotes everywhere and use flake8-quotes to help with this.
msg269883 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-06 12:41
@Terry I've removed the two string quotes changes in the latest patch.

@Berker I spent a small amount of time trying out your proposed super() changes, but could not get them to work on 3.5.1.

"C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\python.exe" "C:/Users/John Hagen/PycharmProjects/test/test.py"
Traceback (most recent call last):
  File "C:/Users/John Hagen/PycharmProjects/test/test.py", line 25, in <module>
    app = Application(master=root)
  File "C:/Users/John Hagen/PycharmProjects/test/test.py", line 6, in __init__
    super().__init__(self, master)
  File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2583, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2131, in __init__
    BaseWidget._setup(self, master, cnf)
  File "C:\Users\John Hagen\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2109, in _setup
    self.tk = master.tk
AttributeError: 'Application' object has no attribute 'tk'

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

import tkinter as tk


class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(self, 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=root.destroy)
        self.quit.pack(side="bottom")

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


root = tk.Tk()
app = Application(master=root)
app.mainloop()
msg269884 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-07-06 13:16
Thanks for the updated patch. I noticed a typo in your test script. It works for me if I update the super() line from

    super().__init__(self, master)

to

    super().__init__(master)
msg269906 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-06 19:57
@Berker, thanks for the tip! I've fixed it up.

I think this latest patch covers everything Berker and Terry have commented about.
msg270350 - (view) Author: John Hagen (John Hagen) * Date: 2016-07-13 23:11
The patch was reviewed and marked ready to commit.  Could someone with commit privileges perform the final commit?  Thanks.
msg270364 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-07-14 04:32
New changeset 453a88a41a58 by Berker Peksag in branch '3.5':
Issue #27455: Improve examples in tkinter documentation
https://hg.python.org/cpython/rev/453a88a41a58

New changeset 800c069e16a0 by Berker Peksag in branch 'default':
Issue #27455: Merge from 3.5
https://hg.python.org/cpython/rev/800c069e16a0
msg270365 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-07-14 04:35
Since Terry is already busy with IDLE maintenance, I went ahead and commit the patch with minor modifications. Thanks for the patch, John! :)
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71642
2016-07-14 04:35:15berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg270365

stage: patch review -> resolved
2016-07-14 04:32:55python-devsetnosy: + python-dev
messages: + msg270364
2016-07-13 23:11:58John Hagensetmessages: + msg270350
2016-07-06 19:57:46John Hagensetfiles: + Fix-tkinter-docs-PEP8.diff

messages: + msg269906
2016-07-06 19:56:10John Hagensetfiles: - 0001-Fix-tkinter-docs-PEP8.diff
2016-07-06 13:16:22berker.peksagsetmessages: + msg269884
2016-07-06 12:41:46John Hagensetfiles: + 0001-Fix-tkinter-docs-PEP8.diff

messages: + msg269883
2016-07-06 12:38:57John Hagensetfiles: - 0001-Fix-tkinter-docs-PEP8.diff
2016-07-05 20:13:25John Hagensetmessages: + msg269850
2016-07-05 19:46:37terry.reedysetcomponents: + Tkinter
2016-07-05 19:46:19terry.reedysetmessages: + msg269845
2016-07-05 17:49:26John Hagensetfiles: + 0001-Fix-tkinter-docs-PEP8.diff

messages: + msg269844
2016-07-05 17:41:39John Hagensetfiles: - 0001-Fix-tkinter-docs-PEP8.patch
2016-07-05 13:41:21berker.peksagsetnosy: + berker.peksag, terry.reedy
messages: + msg269822

type: enhancement
stage: patch review
2016-07-05 13:24:41SilentGhostsetnosy: + SilentGhost
messages: + msg269821
2016-07-05 13:20:52John Hagencreate