Calling a module function in another class..........
Jørgen Cederberg
jorgencederberg at hotmail.com
Fri May 2 02:30:49 EDT 2003
perl lover wrote:
> 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.
Hi Perl Lover (might I suggest a name change? :) )
first of, your indentation is way off. Perhaps it is your mail program,
but i looks all screwed up. Second, the canvas widget doesn't have a
'event' variable. You can merely pass the event variable and print the x
and y coordinates. Below are the corrected programs:
##############################################
# classtest.py
##############################################
def print_mousepos(event):
print event.x,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(event)
root = Tk()
myapp = App(root)
root.mainloop()
HTH
Jorgen Cederberg
More information about the Python-list
mailing list