0
votes

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

1
is your file named "tkinter.py"? - Bryan Oakley
The traceback must have said 'Tkinter', not 'Tk'. Please copy and paste instead of typing what you remember. - Terry Jan Reedy

1 Answers

3
votes

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.