Nov 21, 2009

[python]got A Problem In My Little Program - No reaction when button was pressed

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > Python

[python]got A Problem In My Little Program - No reaction when button was pressed

jedipi
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()

 

 

 


Comment/Reply (w/o sign-up)

gentoo
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

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Pythongot Program Reaction Button Pressed


    Looking for python, problem, program, reaction, button, pressed

See Also,

*SIMILAR VIDEOS*
Searching Video's for python, problem, program, reaction, button, pressed
advertisement



[python]got A Problem In My Little Program - No reaction when button was pressed

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com