Avery Lipsit Avery Lipsit - 1 month ago 6x
Python Question

Why is my code returning "name 'Button' is not defined"?

my code is giving me this error and I can't for the life of me figure out why it's telling me "NameError: name 'Button' is not defined." In Tkinter I thought Button was supposed to add a button?

import Tkinter

gameConsole = Tkinter.Tk()
#code to add widgets will go below

#creates the "number 1" Button
b1 = Button(win,text="One")



A few options available to source the namespace:

  • from Tkinter import Button Import the specific class.

  • import Tkinter -> b1 = Tkinter.Button(win,text="One") Specify the the namespace inline.

  • from Tkinter import * Imports everything from the module.