Python and Root GUI

Is it possible to use Python to script a ROOT GUI application?

The following example doesn’t open a window. If it is possible to open a gui window, how do I keep it from immediately closing?

[code]import ROOT
import os, sys

ROOT.gClient.GetRoot()
fMain = ROOT.TGMainFrame(ROOT.gClient.GetRoot(),300,300)
fMain.SetWindowName(“ROOT GUI”)

fEcanvas = ROOT.TRootEmbeddedCanvas(“Ecanvas”,fMain,800,600)
fMain.AddFrame(fEcanvas, ROOT.TGLayoutHints(ROOT.kLHintsExpandX| ROOT.kLHintsExpandY,10,10,10,1))

fMain.ShowFrame( fEcanvas )
fMain.Activate(1)

print “Does this do anything?”[/code][/code]

Hi Dennis,

Please replace the lines:fMain.ShowFrame( fEcanvas ) fMain.Activate(1) with:fMain.MapSubwindows() fMain.Resize(fMain.GetDefaultSize()) fMain.MapWindow() The MapSubwindows method maps all child frames of fMain; the layout algorithm is called by Resize (to apply TGLayoutHints settings), and in the end, the MapWindow method makes fMain appear on the screen.

Best regards, Ilka

Thanks Ilka. :slight_smile:

Now the window opens but is immediately closed. Is there a way to keep it open until the user closes it?

[code]import ROOT
import os, sys

ROOT.gClient.GetRoot()
fMain = ROOT.TGMainFrame(ROOT.gClient.GetRoot(),300,300)
fMain.SetWindowName(“CTT EXAMINE”)

fEcanvas = ROOT.TRootEmbeddedCanvas(“Ecanvas”,fMain,800,600)
fMain.AddFrame(fEcanvas, ROOT.TGLayoutHints(ROOT.kLHintsExpandX| ROOT.kLHintsExpandY,10,10,10,1))

fMain.MapSubwindows()
dimensions = fMain.GetDefaultSize()
fMain.Resize(dimensions.fWidth,dimensions.fHeight)
fMain.MapWindow()

print “Does this do anything?”[/code] [/quote]

Hi Dennis,

I asked the same question this morning and the answer was to usepython -i your_code.pyCheers, Ilka

:stuck_out_tongue:

That did the trick.