Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的代码返回“名称‘按钮’未定义”?_Python_Tkinter_Pycharm - Fatal编程技术网

Python 为什么我的代码返回“名称‘按钮’未定义”?

Python 为什么我的代码返回“名称‘按钮’未定义”?,python,tkinter,pycharm,Python,Tkinter,Pycharm,我的代码给了我这个错误,我一辈子都不明白为什么它告诉我NameError:name'Button'没有定义。在Tkinter我以为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")

我的代码给了我这个错误,我一辈子都不明白为什么它告诉我NameError:name'Button'没有定义。在Tkinter我以为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()
使用

使用


有几个选项可用于源名称空间:

从Tkinter导入按钮导入特定类

导入Tkinter->b1=Tkinter.Buttonwin,text=One内联指定命名空间

从Tkinter导入*从模块导入所有内容


有几个选项可用于源名称空间:

从Tkinter导入按钮导入特定类

导入Tkinter->b1=Tkinter.Buttonwin,text=One内联指定命名空间

从Tkinter导入*从模块导入所有内容


按钮是TKinter命名空间的一部分。使用TKinter.Button。。。。请记住,对于新的代码库,推荐的解释器版本是Python3。Python 2的支持将于2020年结束。Button是TKinter命名空间的一部分。使用TKinter.Button。。。。请记住,对于新的代码库,推荐的解释器版本是Python3。Python 2的支持将在2020年结束。谢谢,我现在也明白了为什么它会这样做了!谢谢,我现在也明白它为什么这么做了@AveryLisp如果答案解决了您的问题,请记住向上投票和/或选择它。@AveryLisp如果答案解决了您的问题,请记住向上投票和/或选择它。
import Tkinter
b1 = Tkinter.Button(win,text="One")
from Tkinter import Button
b1 = Button(win,text="One")