我有以下内容:
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.menu()
def menu(self):
self.parent.title("Simple menu")
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
configmenu = Menu(menubar, tearoff=0)
configmenu.add_command(label="Add Player", command=self.addplayer)
menubar.add_cascade(label="Config", menu=configmenu)
menubar.add_command(label="Exit", command=self.onexit)
def onexit(self):
self.quit()
def addplayer(self):
toplevel = Toplevel()
toplevel.focus_set()
Label(toplevel, text='first name').grid(row=1, column=0, sticky='W')
fn = Entry(toplevel, text='first name')
fn.grid(row=1, column=1, sticky='W')
indb = insertdb()
Button(toplevel, text='Save', command=indb.foo(fn.get())).grid(row=4, column=0, pady=1)
Button(toplevel, text='Abort', command=toplevel.destroy).grid(row=4, column=1, pady=1)
class insertdb():
def __init__(self):
# db foo
return
def foo(self, fn):
# toplevel.destroy()
print(fn)
这只是一个例子,仍然不完整。我不明白,为什么我没有从 fn.get() 获得任何价值。点击保存按钮后,没有任何反应。