Hi,

I have two modules: Mod1 and Mod2. I want to call the function ‘ ProgressBar’ which is present in Mod1 inside a class ‘clsMain’. In the function ‘ProgressBar’, I set the increment to the progress bar. The function looks something like this:

def ProgressBar(self,intIncrement):
self.gauge1.SetValue(intIncrement)

It takes integer as an input. Self refers to the frame on which it is set.
How would I call this function from Mod2???
Any help is appreciated!!!!

Regards,
Rajendra

Recommended Answers

All 11 Replies

couldnt you just import mod1 into your mod2? That way you could then access all methods.

I tried that... I have imported mod1 into mod2. But its giving the following error: module object has no attribute 'ProgressBar'.
When I call that function within the same module, its working fine.

Regards,
Dinil

Well is ProgressBar inside a class in the module cause then you might have to go:

import mod1
mod1.class.ProgressBar()

yes the function 'ProgressBar' is inside a class 'clsMain’.
I tried mod1.clsMain.ProgressBar()

its still showing the same error.

Regards,
Dinil

why don't you just post Mod1 and Mod2, or attach them to your post ?

Hi,

I have two modules: Mod1 and Mod2. I want to call the function ‘ ProgressBar’ which is present in Mod1 inside a class ‘clsMain’. In the function ‘ProgressBar’, I set the increment to the progress bar. The function looks something like this:

def ProgressBar(self,intIncrement):
self.gauge1.SetValue(intIncrement)

It takes integer as an input. Self refers to the frame on which it is set.
How would I call this function from Mod2???

I have tried this, but its not working!
This function is present in Mod2:

def GetUserInfo():
   
    #Call Function ProgressBar present in Mod1
    progress_bar = Mod1.clsMain(parent)
    progress_bar.ProgressBar(20)

The structure of Mod1 is as follows:

class clsMain(wx.Frame):
    def ProgressBar(self,intIncreament):
         self.gauge1.SetValue(intIncreament)

Any help is appreciated!!!!

Regards,
Dinil

I have attcahed the sample code:
Instead of Mod1 and Mod2, I have renamed it to as frame1 and module2.

In principle, it should work if you put import Mod1 in Mod2. However this will fail if Mod1 imports Mod2, because there should be no cyclic importations in python code. There are ways around this. A solution could be to put the import statement in the function GetUserInfo

def GetUserInfo():
    import Mod1
    #Call Function ProgressBar present in Mod1
    progress_bar = Mod1.clsMain(parent)
    progress_bar.ProgressBar(20)

so that the import Mod1 will only be executed when GetUserInfo is called and not when Mod2 is imported.

I see in your code that frame1.py imports module2 and that module2.py imports frame1, and that's a bad idea :)

Hi,

Its still not working...
Can u please look into the sample code?

Regards,
Dinil

There is an inconsistency in your code. The __init__ function in class Frame1 (which is called when you create a new Frame1 object) calls GetUserInfo which in turn creates a new Frame1 by a call to Frame1.Frame1. This gives an infinite loop.

So, How should I call the function 'ProgressBar' only once?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.