superfersur
superfersur

Reputation: 23

Tkinter name error: "tk" Name is not defined

I am learning how to use Tkinter and I am receiving the following error:

Traceback (most recent call last):
  File "/Users/hetparikh/PycharmProjects/BudCalculator/main.py", line 1, in <module>
    from tkinter import *
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 3, in <module>
    root = Tk()
NameError: name 'Tk' is not defined
from tkinter import *

root = Tk()
theLabel = Label(root, text="This is too easy!")
theLabel.pack()
root.mainloop()

Upvotes: 0

Views: 840

Answers (2)

SuperCoder
SuperCoder

Reputation: 64

import tkinter as tk

root = tk.Tk()
theLabel = tk.Label(root, text="This is too easy!")
theLabel.pack()
root.mainloop()

this should work

Upvotes: 0

BluePigeon
BluePigeon

Reputation: 1812

Try instead:

import tkinter as tk

root = tk.Tk()
label = tk.Label(root, text="This is too easy!")
label.pack()
root.mainloop()

Upvotes: 1

Related Questions