【发布时间】:2013-07-14 16:29:05
【问题描述】:
基本上,问题在于这不起作用:
def run():
print song.get()
def startGUI():
root = Tk()
songLabel = Label(root, text="Enter the song:")
song = Entry(root)
submit = Button(root, text="Download", command = run)
songLabel.pack()
song.pack()
submit.pack()
root.mainloop()
if __name__ == "__main__":
startGUI()
虽然这样做:
def run():
print song.get()
root = Tk()
songLabel = Label(root, text="Enter the song:")
song = Entry(root)
submit = Button(root, text="Download", command = run)
songLabel.pack()
song.pack()
submit.pack()
root.mainloop()
为什么我不能在不出错的情况下将条目放入方法中? 这里的具体错误是在run方法中没有找到'song',给出以下错误:
NameError:未定义全局名称“歌曲”
如何更改它以使此错误不会发生,但条目仍在方法中?
【问题讨论】: