When pressed TButton calls function?

Hello,

Is it possible for TButton to call a C++ function (class member or global) when pressed?

I would like to make a regular TCanvas and plot some graphics on it. I would like to be able to update canvas every time a button is pressed and I thought to use TButton to do this. Is there a better way to do this task?

Thank you,
Rustem

See the example here:
root.cern.ch/doc/master/classTButton.html
You can execute a macro or C++ code

Thanks for the suggestion.

Yes, I saw this but could not get this to work. It turns out that one needs to compile a dictionary for the “button_called_function” - this works now.

void button_called_function()
{
}

int WaitForButton(const std::string &canvas)
{
TDialogCanvas *dialog = new TDialogCanvas(canvas.c_str(), “”, 150, 50);

TButton *but1 = new TButton(“Next”, “button_called_function()”, 0.05, 0.05, 0.95, 0.95);
but1->Draw();

dialog->cd();
return 1;
}

So it works now ?
Note you can also execute a macro.

This works now - thanks!

By the way, I am just trying to write a simple equivalent of TCanvas::WaitPrimitive function that uses an explicit “next” button instead of double-click because my X session is very slow and double-click often does not register. Is there a better way to do this?

Thank you,
Rustem

That’s a good way I guess…