Help with button command runing when created.

For some reason when i created a directgui button it runs the command that it’s supposed to run when i run the game. the button is an instance of a class and i created it like this:

mainMenu.startButton._init_((0,0,0),(.5,.5,.5), ("Start"),mainMenu.changeArea(sol))

And then there is a different method that turns all that information into a directGUIButton

    def create(self):
        self.button = DirectButton(pos = self.pos, scale = self.scale ,text = self.text, command = self.command)

Now for some reason when i start the game it runs te command but when i click on the button nothing happens.
Is there something im doing wrong?

That’s because you actually run mM.cA().
You should only pass mM.cA to DirectButton’s command.
If you want to pass arguments to mM.cA, use the keyword extraArgs=[theArgs].

ok i did this now:

    def create(self):
        self.button = DirectButton(pos = self.pos, scale = self.scale ,text = self.text, command = self.command, extraArgs = [self.extraArg1, self.extraArg2])

and so here is all the information for that specific button:

mainMenu.startButton._init_((0,0,0),(.5,.5,.5), ("Start"),area.changeArea(), mainMenu, sol)

but now i get the error:

    mainMenu.startButton._init_((0,0,0),(.5,.5,.5), ("Start"),area.changeArea(), mainMenu, sol)
TypeError: unbound method changeArea() must be called with area instance as first argument (got nothing instead)
  1. area is a class
  2. mainMenu is area instance
  3. passing and calling are 2 different things, if you only need to pass changeArea, don’t append the (), because that indicates you want to actually run it.

Why don’t you stick to your first code ?
That would be : …, (“Start”), mainMenu.changeArea, sol)

Thanks for your help