[Tutor] Just Learning Python
Mark Brown
mark.brown@rogers.com
Wed Oct 30 19:15:02 2002
I'm just learning Python and found a simple program that I'm trying to
convert to using 'class'.
The main program is 'runit2.py':
#!/usr/bin/env python
from runit2ui import *
app1 = App1()
app1.mainloop()
The user interface program is 'runit2ui.py':
#!/usr/bin/env python
from Tkinter import *
from os import system
from sys import exit
class App1:
def __init__(self):
root = Tk()
root.title('PyRun')
label = Label(root, text="Run")
label.pack(side=LEFT)
entry = Entry(root, takefocus=TRUE)
entry.pack(side=LEFT, fill=X, expand=TRUE)
entry.bind('<Key-Return>', runit)
entry.focus()
def runit(event):
text = entry.get()
command = "%s &" % text
system(command)
exit(0)
When 'runit2.py' is run the following error is reported:
Traceback (most recent call last):
File "/home/mark/Projects/project2/runit2.py", line 5, in ?
app1 = App1()
File "/home/mark/Projects/project2/runit2ui.py", line 15, in __init__
entry.bind('<Key-Return>', runit)
NameError: global name 'runit' is not defined
What needs to be changed to get by this error?
Thanks
Mark