Avery Lipsit Avery Lipsit - 1 year ago 66
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")


Answer Source

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.

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