import function from user defined modules

Discussion in 'Python' started by groves, Aug 27, 2006.

  1. groves

    groves Guest

    Can anybody give me an example of how to import a function of module X
    in module y. And please if yu can use classes(Object oriented approach)
    would be great.

    The problem is that I have created a text on canvas, and now I want
    that whenever a user right clicks on it, the option COMMAND should
    invoke a function defined in some other module say Y.

    thanks a lot to all who will look into problem, any help would be
    appreciated.
     
    groves, Aug 27, 2006
    #1
    1. Advertisements

  2. groves

    Simon Forman Guest

    groves wrote:
    > Can anybody give me an example of how to import a function of module X
    > in module y. And please if yu can use classes(Object oriented approach)
    > would be great.
    >
    > The problem is that I have created a text on canvas, and now I want
    > that whenever a user right clicks on it, the option COMMAND should
    > invoke a function defined in some other module say Y.
    >
    > thanks a lot to all who will look into problem, any help would be
    > appreciated.


    from X import func

    Then you can call func() in your module.

    Peace,
    ~Simon
     
    Simon Forman, Aug 28, 2006
    #2
    1. Advertisements

  3. groves wrote:

    > Can anybody give me an example of how to import a function of module X
    > in module y. And please if yu can use classes(Object oriented approach)
    > would be great.
    >
    > The problem is that I have created a text on canvas, and now I want
    > that whenever a user right clicks on it, the option COMMAND should
    > invoke a function defined in some other module say Y.


    import Y

    widget = Canvas(..., command=Y.function)

    for more on this, see the tutorial:

    http://docs.python.org/tut/node8.html

    </F>
     
    Fredrik Lundh, Aug 28, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guilherme Pinto
    Replies:
    1
    Views:
    435
    Victor Bazarov
    Oct 10, 2003
  2. Remy Cool
    Replies:
    1
    Views:
    539
    Remy Cool
    Aug 27, 2003
  3. Walter Brunswick

    Importing User-defined Modules

    Walter Brunswick, Jul 24, 2005, in forum: Python
    Replies:
    3
    Views:
    384
    Walter Brunswick
    Jul 26, 2005
  4. groves
    Replies:
    0
    Views:
    289
    groves
    Aug 27, 2006
  5. Oodini
    Replies:
    1
    Views:
    2,037
    Keith Thompson
    Sep 27, 2005
  6. Gregor Stich

    jython: user-defined modules

    Gregor Stich, Apr 25, 2007, in forum: Python
    Replies:
    1
    Views:
    370
    Diez B. Roggisch
    Apr 25, 2007
  7. Replies:
    1
    Views:
    670
    Sion Arrowsmith
    Jul 10, 2008
  8. Alok
    Replies:
    3
    Views:
    472
Loading...