r/programminghelp • • Nov 23 '21

Python Please i dont know whats wrong

code:

from tkinter import *
tk=Tk()
l=Label(tk,text="hehehehe")
l.pack()
tk.mainloop()

error:

Exception has occurred: NameError

name 'Tk' is not defined

Please tell me whats wrong... Im using python 3.10.0 and have installed Tkinter... but i cant move beyond the tk=Tk() error.

4 Upvotes

5 comments sorted by

1

u/[deleted] Nov 23 '21

What tutorial are you following?

Instead of:

from tkinter import *

you should have used

import tkinter as tk

1

u/[deleted] Nov 23 '21

I followed a random one YouTube… after that I’ve been seeing codes on stack overflow. None of them work

1

u/[deleted] Nov 23 '21

Make sure all tutorials you use are also for Python 3.6+, anything older, or for Python 2.7~ will give you issues.

1

u/[deleted] Nov 23 '21

Thanks a lot!!! i dont know what happened but somehow it works now!!! Thanks a lot

1

u/[deleted] Nov 23 '21

It wasn't working in your deleted comment because you forgot the parenthesis after Tk.

tk.Tk()