NameError: name 'tk' is not defined repl.it NameError: name 'tk' is not defined repl.it tkinter tkinter

NameError: name 'tk' is not defined repl.it


repl.it has nothing to do with the issue. You have lines referencing "tk", like app = tk.Tk(), but you never defined anything called tk. It looks like some of your code expects you to have imported Tkinter via import tkinter as tk, in which case tk would be valid. But you also have code expecting it to be called tkinter, like root = tkinter.Tk(). It seems like your code was inspired from multiple sources, some of which had Tkinter imported as tk, and some where it was imported as tkinter. All you have to do is replace all tks with tkinter. For example, this line:

Def_Btn = tk.Button(app,text='Default Button')

would become:

Def_Btn = tkinter.Button(app,text='Default Button')


The problem is probably coming from your import

I observed that you did not import Tkinter as tk but you keep on using the tk. try importing it


Since you have:

import tkinter

Python looks for tkinter not tk since you have not told python that you want to use the module with the alias 'tk'

Your solution is:

import tkinter as tk

You probably forgot that you were using tkinter instead of tk.