Calling a module function in another class..........

perl lover hemanexp at yahoo.com
Thu May 1 23:38:03 EDT 2003


hi,
   How to call a member function of one module from
another class function? i have created a module and
defined a function in that. I called this function
from another class. But i got some errror message. My
program is given below.

##############################################
#               classtest.py
##############################################

def print_mousepos(self,event):
        print self.canvas.event.x,self.canvas.event.y


#############################################
# mainprg.py
#############################################
import classtest
from Tkinter import *
class App:
       def __init__(self,parent):
               self.myparent = parent
               self.canvas =
Canvas(parent,width="1000m",height="1000m")


self.canvas.create_rectangle(100,100,200,200,fill='blue')
               
self.canvas.bind('<B1-ButtonRelease>',self.ZoomIn)

self.canvas.bind('<Motion>',self.mousemove)
                self.canvas.pack()

       def ZoomIn(self,event):
               self.canvas.scale(ALL,2,2,1.5,1.5)

       def mousemove(self,event):
                classtest.print_mousepos(self,event)

 root = Tk()
 myapp =  App(root)
 root.mainloop()

  Here i called "print_mousepos"  of classtest.py
module in my "App" class and want to print the mouse
position values. But i got the following error:

File "  mainprg.py", line -- in mousemove
NameError:print_mousepos

        Now how can i rectify this error and call a
member
function of a module in another calss?

  Thanx



__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list