Basically, the problem is that this doesn't work:
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()
Whereas this does:
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()
Why is it that I can't place an entry into a method without getting errors? The specific error here is that 'song' isn't being found in the run method, giving the following error:
NameError: global name 'song' is not defined
How do I change it so that this error doesn't happen, but the entry is still in a method?