0

I have tried all the hello world for tkinter and python 3.5 on my PC 64 bit Windows 8 but it doesn't work...

from tkinter import *

class Application(Frame):

    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        self.myButton = Button(self, text='Button Label')
        self.myButton.grid()

    root = Tkinter.Tk()

    root.title('Frame w/ Button')
    root.geometry('200x200')

    app = Application(root)
    root.mainloop()

This code gives me the error NameError: name 'Tk' is not defined

I am grateful for any help, Alain

2
  • is your file named "tkinter.py"? Commented Oct 20, 2015 at 22:17
  • The traceback must have said 'Tkinter', not 'Tk'. Please copy and paste instead of typing what you remember. Commented Oct 20, 2015 at 23:52

1 Answer 1

3

If you look at your code you write

from tkinter import *

Then you use

root = Tkinter.Tk()

Why didn't you try

root = Tk()

?

Because you are importint everything from tkinter you do not need to use the module to access Tk(). And you have a typo too in your mentioned line: the module's name starts with a lowercase t.

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

1 Comment

Name 'tkinter' is also not defined after the * import, so 'tkinter.Tk()' is not an option. Your change to 'root = Tk()' is the only way.

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.