0

I'm new to Python 3 programming and are getting errors that I can't seem to fix. I'm trying to make a text editor. This is the code:

import tkinter as tk


class PyText:

    def __init__(self, master):
        master.title("Untitled - PyText")
        master.geometry("1200x700")


if __name__ == "__main__":
    master = tk.TK()
    pt = PyText(master)
    master.mainloop()

Running it I get: Traceback (most recent call last): File "textEdit.py", line 12, in master = tk.TK() AttributeError: module 'tkinter' has no attribute 'TK'

How can I fix this??? Thank you for the help!

1
  • 2
    The error is telling you the problem. There is no attribute named TK. It's Tk. Commented Oct 18, 2019 at 12:28

1 Answer 1

2

The problem is that you use tk.TK(), but you should use tk.Tk(), with small 'k'. Also, you should probably use self.master in __init__ function:

    def __init__(self, master):
        self.master = master
        self.master.title("Untitled - PyText")
        self.master.geometry("1200x700")

Then the link to a master object is preserved inside the pt object as pt.master. Hope that's helpful!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.