Home Ask Login Register

Developers Planet

Your answer is one click away!

user3293837 February 2016

Problems with creating a window using tkinter

I am trying to create a program using tkinter and it keeps on giving me this one error:

in __init__ self.master = TK()
NameError: name 'TK' is not defined

I am not sure why it is saying that TK isn't defined when I am importing tkinter, can someone please explain what I am doing wrong.

Here is my code:

from tkinter import *

class App:
    def __init__(self):
        self.master = TK()
        frame = Frame(self.master)
        self.master.title("Music Player")

myapp = App()


zondo February 2016

It shouldn't be TK; it should be Tk.

Sнаđошƒаӽ February 2016

It's Tk, not TK. Take a look at this small code given in the documentation of tkinter. The last three lines are here for you.

import tkinter as tk

root = tk.Tk()
app = Application(master=root)

As a matter of fact, I think you were trying the code from the documentation page, yet you missed it!

Post Status

Asked in February 2016
Viewed 3,917 times
Voted 4
Answered 2 times


Leave an answer

Quote of the day: live life