Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
numberEntry.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_gui
3## Example frame with one box where the user can increase or decrease a number
4## and the shown value will be updated accordingly.
5##
6## \macro_code
7##
8## \author Wim Lavrijsen
9
10import ROOT
11
12
13class pMyMainFrame(ROOT.TGMainFrame):
14 def __init__(self, parent, width, height):
15 ROOT.TGMainFrame.__init__(self, parent, width, height)
16
17 self.fHor1 = ROOT.TGHorizontalFrame(self, 60, 20, ROOT.kFixedWidth)
18 self.fExit = ROOT.TGTextButton(self.fHor1, "&Exit", "gApplication->Terminate(0)")
19 self.fExit.SetCommand('TPython::Exec( "raise SystemExit" )')
20 self.fHor1.AddFrame(self.fExit, ROOT.TGLayoutHints(
21 ROOT.kLHintsTop | ROOT.kLHintsLeft | ROOT.kLHintsExpandX, 4, 4, 4, 4))
22 self.AddFrame(self.fHor1, ROOT.TGLayoutHints(ROOT.kLHintsBottom | ROOT.kLHintsRight, 2, 2, 5, 1))
23
24 self.fNumber = ROOT.TGNumberEntry(self, 0, 9, 999, ROOT.TGNumberFormat.kNESInteger,
25 ROOT.TGNumberFormat.kNEANonNegative,
26 ROOT.TGNumberFormat.kNELLimitMinMax,
27 0, 99999)
28 self.fLabelDispatch = ROOT.TPyDispatcher(self.DoSetlabel)
29 self.fNumber.Connect("ValueSet(Long_t)", "TPyDispatcher", self.fLabelDispatch, "Dispatch()")
30 self.fNumber.GetNumberEntry().Connect("ReturnPressed()", "TPyDispatcher", self.fLabelDispatch, "Dispatch()")
31 self.AddFrame(self.fNumber, ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsLeft, 5, 5, 5, 5))
32 self.fGframe = ROOT.TGGroupFrame(self, "Value")
33 self.fLabel = ROOT.TGLabel(self.fGframe, "No input.")
34 self.fGframe.AddFrame(self.fLabel, ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsLeft, 5, 5, 5, 5))
35 self.AddFrame(self.fGframe, ROOT.TGLayoutHints(ROOT.kLHintsExpandX, 2, 2, 1, 1))
36
37 self.SetCleanup(ROOT.kDeepCleanup)
38 self.SetWindowName("Number Entry")
39 self.MapSubwindows()
40 self.Resize(self.GetDefaultSize())
41 self.MapWindow()
42
43 def __del__(self):
44 self.Cleanup()
45
46 def DoSetlabel(self):
47 self.fLabel.SetText(ROOT.Form("%d" % self.fNumber.GetNumberEntry().GetIntNumber()))
48 self.fGframe.Layout()
49
50
51if __name__ == "__main__":
52 window = pMyMainFrame(ROOT.gClient.GetRoot(), 50, 50)