Reputation: 43
I'm trying to make a basic window with the text "t" inside using Tkinter, however when running the code the shell spits out "NameError: name 'Label' is not defined". I'm running Python 3.5.2.
I followed the tutorials but the problem is in the label = Label(root, text="test")
line.
import tkinter
root = tkinter.Tk()
sheight = root.winfo_screenheight()
swidth = root.winfo_screenwidth()
root.minsize(width=swidth, height=sheight)
root.maxsize(width=swidth, height=sheight)
label = Label(root, text="test")
label1.pack()
root = mainloop()
Is the label function different in 3.5.2?
Upvotes: 1
Views: 28329
Reputation: 1
It's a typo error... Nothing to do with the import statements.
Label = with a capital L not l
Upvotes: 0
Reputation: 66
On Windows Operating System your code should run well but on macOS, you will get a problem. I don't know why something like that happen. Anyway try:
import tkinter,
from tkinter import*
And run
After that just write:
from tkinter import *
or
import tkinter
(not both this time)
Upvotes: 0
Reputation: 1
stumbled across the same Problem. Most beginners guides seem to mess up here. I had to use a second line in the configuration:
import tkinter from tkinter import *
...
Upvotes: 0
Reputation: 23480
import tkinter
root = tkinter.Tk()
sheight = root.winfo_screenheight()
swidth = root.winfo_screenwidth()
root.minsize(width=swidth, height=sheight)
root.maxsize(width=swidth, height=sheight)
label = tkinter.Label(root, text="test")
label1.pack()
root = tkinter.mainloop() # <- prob need to fix this as well.
Because you didn't do from tkinter import *
you need to invoke the Label from the tkinter module.
Alternatively you can do:
from tkinter import *
...
label = Label(root, text="test")
Upvotes: 0
Reputation: 191681
You never imported the Label
class. Try tkinter.Label
Check the import statements for those tutorials
Maybe they imply from tkinter import *
Upvotes: 7