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

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

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

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.

This article has been dead for over six months. Start a new discussion instead.