[Tutor] Just Learning Python

alan.gauld@bt.com alan.gauld@bt.com
Thu Oct 31 12:41:03 2002


 
> class App1:
> 	def __init__(self):
>             root = Tk()
...
>             entry = Entry(root, takefocus=TRUE)

And since you access entry within runit you need to store it as a 
class variable, hence use self.entry
 
>             entry.bind('<Key-Return>', runit)

You need to bind self.runit. Otherwise Python is looking for a function
in the global namespace called runit...

>         def runit(event):

As a method this must have a patrameter referencing the class instance
first, thus you need:

          def runit(self, event):

>             text = entry.get()

And since entry is a class variable(see above) you need to access it as
self.entry

>             command = "%s &" % text
>             system(command)

Personally I'd probably just do:

             system(self.entry.get() + ' &')

and miss out the other stuff.
However if you might start adding arguments to the command then your 
approach is better...

> NameError: global name 'runit' is not defined

Thats the lack of self in front of the runit refeence.
But you need to fix the other bits too...

Alan g.