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")
gameConsole.wm_title("Console")
gameConsole.mainloop()
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.
Use
import Tkinter
b1 = Tkinter.Button(win,text="One")
or
from Tkinter import Button
b1 = Button(win,text="One")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.