def onMakeCommand(self): new = Toplevel() # a new top-level window new.title('Enter Python command') # arbitrary python code frm = frame(new, TOP) label(frm, LEFT, '>>>') ent = StringVar() entry(frm, LEFT, ent) button(frm, RIGHT, 'Run', lambda s=self, e=ent: s.onCommand(e))
def __init__(self, **args): Toplevel.__init__(self) label(self, TOP, 'PyCalc Plus - Container') self.calc = apply(CalcGui, (self, ), args) frm = frame(self, BOTTOM) extras = [('sqrt', 'sqrt(%s)'), ('x^2 ', '(%s)**2'), ('x^3 ', '(%s)**3'), ('1/x ', '1.0/(%s)')] for (lab, expr) in extras: button(frm, LEFT, lab, (lambda m=self.onExtra, e=expr: m(e))) button(frm, LEFT, ' pi ', self.onPi)
def __init__(self, **args): Toplevel.__init__(self) label(self, TOP, 'PyCalc Plus - Container') self.calc = apply(CalcGui, (self,), args) frm = frame(self, BOTTOM) extras = [('sqrt', 'sqrt(%s)'), ('x^2 ', '(%s)**2'), ('x^3 ', '(%s)**3'), ('1/x ', '1.0/(%s)')] for (lab, expr) in extras: button(frm, LEFT, lab, (lambda m=self.onExtra, e=expr: m(e)) ) button(frm, LEFT, ' pi ', self.onPi)
def __init__(self, parent=None): # an extended frame Frame.__init__(self, parent) # on default top-level self.pack(expand=YES, fill=BOTH) # all parts expandable self.master.title('Python Calculator 0.1') # 6 frames plus entry self.master.iconname("pcalc1") self.names = {} # namespace for variables text = StringVar() entry(self, TOP, text) rows = ["abcd", "0123", "4567", "89()"] for row in rows: frm = frame(self, TOP) for char in row: button(frm, LEFT, char, lambda x=text, y=char: x.set(x.get() + y)) frm = frame(self, TOP) for char in "+-*/=": button(frm, LEFT, char, lambda x=text, y=char: x.set(x.get() + ' ' + y + ' ')) frm = frame(self, BOTTOM) button(frm, LEFT, 'eval', lambda x=self, y=text: x.eval(y)) button(frm, LEFT, 'clear', lambda x=text: x.set(''))
def __init__(self, parent=None): # an extended frame Frame.__init__(self, parent) # on default top-level self.pack(expand=YES, fill=BOTH) # all parts expandable self.master.title('Python Calculator 0.1') # 6 frames plus entry self.master.iconname("pcalc1") self.names = {} # namespace for variables text = StringVar() entry(self, TOP, text) rows = ["abcd", "0123", "4567", "89()"] for row in rows: frm = frame(self, TOP) for char in row: button(frm, LEFT, char, lambda x=text, y=char: x.set(x.get() + y)) frm = frame(self, TOP) for char in "+-*/=": button(frm, LEFT, char, lambda x=text, y=char: x.set(x.get()+' '+y+' ')) frm = frame(self, BOTTOM) button(frm, LEFT, 'eval', lambda x=self, y=text: x.eval(y) ) button(frm, LEFT, 'clear', lambda x=text: x.set('') )
def makeWidgets(self): # 7 frames plus text-entry entry(self, TOP, self.text) rows = ["abcd", "0123", "4567", "89()"] for row in rows: frm = frame(self, TOP) for char in row: button(frm, LEFT, char, lambda x=self, y=char: x.onOperand(y)) frm = frame(self, TOP) for char in "+-*/=": button(frm, LEFT, char, lambda x=self, y=char: x.onOperator(y)) frm = frame(self, TOP) button(frm, LEFT, 'cmd', self.onMakeCommand) button(frm, LEFT, 'dot', lambda x=self: x.onOperand('.')) button(frm, LEFT, 'help', self.help) button(frm, LEFT, 'quit', self.quit) # from guimixin frm = frame(self, BOTTOM) button(frm, LEFT, 'eval', self.onEval) button(frm, LEFT, 'clear', self.onClear)
from calculator import CalcGui, getCalcArgs from PP2E.Dbase.TableBrowser.guitools import frame, button, label class CalcGuiPlus(Toplevel): def __init__(self, **args): Toplevel.__init__(self) label(self, TOP, 'PyCalc Plus - Container') self.calc = apply(CalcGui, (self,), args) frm = frame(self, BOTTOM) extras = [('sqrt', 'sqrt(%s)'), ('x^2 ', '(%s)**2'), ('x^3 ', '(%s)**3'), ('1/x ', '1.0/(%s)')] for (lab, expr) in extras: button(frm, LEFT, lab, (lambda m=self.onExtra, e=expr: m(e)) ) button(frm, LEFT, ' pi ', self.onPi) def onExtra(self, expr): text = self.calc.text eval = self.calc.eval try: text.set(eval.runstring(expr % text.get())) except: text.set('ERROR') def onPi(self): self.calc.text.set(self.calc.eval.runstring('pi')) if __name__ == '__main__': root = Tk() button(root, TOP, 'Quit', root.quit) apply(CalcGuiPlus, (), getCalcArgs()).mainloop() # -bg,-fg to calcgui
class CalcGuiPlus(Toplevel): def __init__(self, **args): Toplevel.__init__(self) label(self, TOP, 'PyCalc Plus - Container') self.calc = apply(CalcGui, (self, ), args) frm = frame(self, BOTTOM) extras = [('sqrt', 'sqrt(%s)'), ('x^2 ', '(%s)**2'), ('x^3 ', '(%s)**3'), ('1/x ', '1.0/(%s)')] for (lab, expr) in extras: button(frm, LEFT, lab, (lambda m=self.onExtra, e=expr: m(e))) button(frm, LEFT, ' pi ', self.onPi) def onExtra(self, expr): text = self.calc.text eval = self.calc.eval try: text.set(eval.runstring(expr % text.get())) except: text.set('ERROR') def onPi(self): self.calc.text.set(self.calc.eval.runstring('pi')) if __name__ == '__main__': root = Tk() button(root, TOP, 'Quit', root.quit) apply(CalcGuiPlus, (), getCalcArgs()).mainloop() # -bg,-fg to calcgui