|
|
|
|
![]() ![]() |
Mar 28 2005, 01:29 AM
Post
#1
|
|
|
Premium Member Group: Members Posts: 352 Joined: 2-March 05 From: Australia Member No.: 2,859 |
I am a newbie in Python.
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() |
|
|
|
May 16 2005, 08:06 AM
Post
#2
|
|
|
Member [ Level 1 ] Group: Members Posts: 37 Joined: 24-January 05 Member No.: 2,319 |
QUOTE(jedipi @ Mar 28 2005, 09:29 AM) I am a newbie in Python. 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() Python is sensitive to indent. I am not sure whether it is the reason. But , at least , these run well on my gentoo box: CODE #!/usr/bin/env python 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() QUOTE chmod u+x test.py
./test.py |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 11th October 2008 - 02:59 PM |