Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gui_ex.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_pyroot
3## A Simple GUI Example
4##
5## \macro_code
6##
7## \author Wim Lavrijsen
8from __future__ import print_function
9
10import os, sys, ROOT
11
12def pygaus( x, par ):
13 import math
14 if (par[2] != 0.0):
15 arg1 = (x[0]-par[1])/par[2]
16 arg2 = (0.01*0.39894228)/par[2]
17 arg3 = par[0]/(1+par[3])
18
19 gauss = arg3*arg2*math.exp(-0.5*arg1*arg1)
20 else:
21 print('returning 0')
22 gauss = 0.
23 return gauss
24
25tpygaus = ROOT.TF1( 'pygaus', pygaus, -4, 4, 4 )
26tpygaus.SetParameters( 1., 0., 1. )
27
28def MyDraw():
29 btn = ROOT.BindObject( ROOT.gTQSender, ROOT.TGTextButton )
30 if btn.WidgetId() == 10:
31 global tpygaus, window
32 tpygaus.Draw()
33 ROOT.gPad.Update()
34
35m = ROOT.TPyDispatcher( MyDraw )
36
37
38class pMainFrame( ROOT.TGMainFrame ):
39 def __init__( self, parent, width, height ):
40 ROOT.TGMainFrame.__init__( self, parent, width, height )
41
42 self.Canvas = ROOT.TRootEmbeddedCanvas( 'Canvas', self, 200, 200 )
43 self.AddFrame( self.Canvas, ROOT.TGLayoutHints(ROOT.kLHintsExpandX | ROOT.kLHintsExpandY) )
44 self.ButtonsFrame = ROOT.TGHorizontalFrame( self, 200, 40 )
45
46 self.DrawButton = ROOT.TGTextButton( self.ButtonsFrame, '&Draw', 10 )
47 self.DrawButton.Connect( 'Clicked()', "TPyDispatcher", m, 'Dispatch()' )
48 self.ButtonsFrame.AddFrame( self.DrawButton, ROOT.TGLayoutHints() )
49
50 self.ExitButton = ROOT.TGTextButton( self.ButtonsFrame, '&Exit', 20 )
51 self.ExitButton.SetCommand( 'TPython::Exec( "raise SystemExit" )' )
52 self.ButtonsFrame.AddFrame( self.ExitButton, ROOT.TGLayoutHints() )
53
54 self.AddFrame( self.ButtonsFrame, ROOT.TGLayoutHints() )
55
56 self.SetWindowName( 'My first GUI' )
57 self.MapSubwindows()
58 self.Resize( self.GetDefaultSize() )
59 self.MapWindow()
60
61 def __del__(self):
62 self.Cleanup()
63
64
65if __name__ == '__main__':
66 window = pMainFrame( ROOT.gClient.GetRoot(), 200, 200 )