[docs] [issue27455] Fix tkinter examples to be PEP8 compliant

John Hagen report at bugs.python.org
Wed Jul 6 08:41:47 EDT 2016


John Hagen added the comment:

@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()

----------
Added file: http://bugs.python.org/file43641/0001-Fix-tkinter-docs-PEP8.diff

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


More information about the docs mailing list