Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> [python]got A Problem In My Little Program, No reaction when button was pressed
jedipi
post Mar 28 2005, 01:29 AM
Post #1


Premium Member
Group Icon

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()
Go to the top of the page
 
+Quote Post
gentoo
post May 16 2005, 08:06 AM
Post #2


Member [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Python(5)
  2. Python (win32)(1)
  3. Python Versus Java ?(4)
  4. Prove Yourself As A Python Coder - Challenge Site(4)
  5. Pagerank Checksum Algo For Python(0)
  6. Lpt Port And Python(0)
  7. Localizing Python(1)
  8. Python Mysqldb Threading(0)


 



- Lo-Fi Version Time is now: 11th October 2008 - 02:59 PM