class Editor():
def __init__(self):
self=Tkinter.Tk()
EditedSongName=StringVar()
EditedArtistName=StringVar()
SongNameLabel = Label(self, text="Song Name:")
SongNameLabel.pack()
SongNameEntry = Entry( self,textvariable=EditedSongName)
SongNameEntry.pack()
ArtistNameLabel = Label(self, text="Artist Name:")
ArtistNameLabel.pack()
ArtistNameEntry = Entry( self,textvariable=EditedArtistName)
ArtistNameEntry.pack()
EditOkButton = Button( self, text="Ok", command=EditOk )
EditOkButton.pack(anchor=CENTER)
self.mainloop()
def EditOk(self):
print "RSAOJ"
Root.canvas.delete(SongName)
SongName=canvas.create_text(650,30,text = EditedSongName,fill = 'black',font=("Times New Roman",35) )
canvas.pack()
Root.canvas.delete(ArtistName)
ArtistName=canvas.create_text(650,90,text = EditedArtistName,fill = 'black',font=("Times New Roman",20) )
canvas.pack()
self.destroy()
无论我如何更改功能,总会出现错误。 NameError:未定义全局名称“EditOk” 那是什么意思?我仍然无法得到阶级和自我的概念。
答案 0 :(得分:1)
尝试
EditOkButton = Button( self, text="Ok", command=self.EditOk )
而不是
EditOkButton = Button( self, text="Ok", command=EditOk )
该方法仅针对特定实例
定义