AgentL3r AgentL3r - 1 year ago 162
Python Question

Labels not defined in Python 3.5.2?

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")

root = mainloop()

Is the label function different in 3.5.2?

Answer Source

You never imported the Label class. Try tkinter.Label

Check the import statements for those tutorials

Maybe they imply from tkinter import *

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download