Standalone TBrowser

Hi, I’m trying to create a standalone TBrowser. That is, I could type tbrowser at the command line and the program pops up. When I click close, it closes. With this it would be possible to double-click on a ROOT file and have it automatically open in TBrowser.

This is a little more difficult than I thought though. The main problem is getting the program to close as TBrowser won’t close a TApplication by default. Here’s my code so far, trying to get it to work. Advice would be much appreciated.

// KRootBrowser.h

#include <TQObject.h>
#include <RQ_OBJECT.h>
#include <TRootBrowser.h>

class KRootBrowser : public TRootBrowser {

virtual ~KRootBrowser();
void CloseWindow();

ClassDef(KRootBrowser,0) //ROOT native GUI version of browser

// --------------------------------------------------------------------

// KRootBrowser.cpp

#include <TApplication.h>
#include <TGClient.h>
#include <TBrowser.h>
#include “KRootBrowser.h”


void KRootBrowser::CloseWindow()

int main(int argc, char **argv)

    TApplication app("App", &argc, argv);
    KRootBrowser *kb = new KRootBrowser();
    TBrowser *tb = kb->Browser();

    return 0;



#pragma link C++ class KRootBrowser;


Compile with :
rootcint -f KDict.cpp -c KRootBrowser.h KLinkDef.h
g++ -Wall -g KRootBrowser.cpp KDict.cpp root-config --cflags --glibs -o tbrowser

Right, I’ve decided. Sod c++ I hate it anyway.

If you’ve pyroot set up, it’s easy. If not, set up pyroot like this:

bash: export PYTHONPATH=$PYTHONPATH:/path/to/root/lib
bash: setenv PYTHONPATH $PYTHONPATH:/path/to/root/lib

So here’s my quick and dirty tbrowser script:

#!/usr/bin/env python

from ROOT import TBrowser, TFile
import time, sys

if len(sys.argv)>1 :

tb = TBrowser()
while tb :

if f :


another very easy way is to have a macro startbrowser.C:
void startbrowser() { new TBrowser(_file0->GetName(), _file0); }
and then (for windows) edit the file associations such that root files are opened by root -l “%1” whereverThatScriptIs\startbrowser.C Obviously, that’s platform independent, and also works for KDE etc.


Yeah, but that leaves you with a stagnant root session. You need something that will quit root when you click close. Otherwise you’ve loads of memory just sitting there.