After read some parts of 《OReilly - ProgrammingPython2ndEd.chm》,
I try to write a small problem as following.
But it is no reaction when I press the button.
Does anyone can tell me why?
CODE
from Tkinter import * # get widget classes
class Inputer(Frame): # subclass our GUI
def __init__(self, parent=None): # constructor method
Frame.__init__(self, parent)
self.pack()
ent = Entry(self)
ent.insert(0, 'Type words here') # set text
ent.pack(side=LEFT) # grow horiz
ent.focus() # save a click
ent.bind('<Return>', (lambda event: self.input(ent.get()))) # on enter key
widget = Button(self, text='Query', command=self.input(ent.get()))
widget.pack(side=RIGHT)
def input(self,text):
print text
if __name__ == '__main__': Inputer().mainloop()
class Inputer(Frame): # subclass our GUI
def __init__(self, parent=None): # constructor method
Frame.__init__(self, parent)
self.pack()
ent = Entry(self)
ent.insert(0, 'Type words here') # set text
ent.pack(side=LEFT) # grow horiz
ent.focus() # save a click
ent.bind('<Return>', (lambda event: self.input(ent.get()))) # on enter key
widget = Button(self, text='Query', command=self.input(ent.get()))
widget.pack(side=RIGHT)
def input(self,text):
print text
if __name__ == '__main__': Inputer().mainloop()


