Exemplo n.º 1
0
 def makeWidgets(self, *args):
     label(self, TOP, 'PyCalc Plus - Subclass')
     CalcGui.makeWidgets(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 expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
Exemplo n.º 2
0
 def __init__(self, **args):
     Toplevel.__init__(self)
     label(self, TOP, 'PyCalc Plus - Container')
     self.calc = 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 expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
 def makeWidgets(self, *args):
     label(self, TOP, 'PyCalc Plus - Subclass')
     CalcGui.makeWidgets(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 expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
Exemplo n.º 4
0
 def onMakeCmdline(self):
     new = Toplevel()  # new top-level window
     new.title('PyCalc command line')  # arbitrary Python code
     frm = frame(new, TOP)  # only the Entry expands
     label(frm, LEFT, '>>>').pack(expand=NO)
     var = StringVar()
     ent = entry(frm, LEFT, var, width=40)
     onButton = (lambda: self.onCmdline(var, ent))
     onReturn = (lambda event: self.onCmdline(var, ent))
     button(frm, RIGHT, 'Run', onButton).pack(expand=NO)
     ent.bind('<Return>', onReturn)
     var.set(self.text.get())
Exemplo n.º 5
0
 def onMakeCmdline(self):
     new = Toplevel()                            # new top-level window
     new.title('PyCalc command line')            # arbitrary Python code
     frm = frame(new, TOP)                       # only the Entry expands
     label(frm, LEFT, '>>>').pack(expand=NO)
     var = StringVar()
     ent = entry(frm, LEFT, var, width=40)
     onButton = (lambda: self.onCmdline(var, ent))
     onReturn = (lambda event: self.onCmdline(var, ent))
     button(frm, RIGHT, 'Run', onButton).pack(expand=NO)
     ent.bind('<Return>', onReturn)
     var.set(self.text.get())
Exemplo n.º 6
0
 def __init__(self, **args):
     Toplevel.__init__(self)
     label(self, TOP, 'PyCalc Plus - Container')
     self.calc = 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 expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
Exemplo n.º 7
0
    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 char=char: text.set(text.get() + char))

        frm = frame(self, TOP)
        for char in "+-*/=":
            button(frm, LEFT, char,
                        lambda char=char: text.set(text.get()+ ' ' + char + ' '))

        frm = frame(self, BOTTOM)
        button(frm, LEFT, 'eval',  lambda: self.eval(text) )
        button(frm, LEFT, 'clear', lambda: text.set('') )
Exemplo n.º 8
0
    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 char=char: text.set(text.get() + char))

        frm = frame(self, TOP)
        for char in "+-*/=":
            button(frm,
                   LEFT,
                   char,
                   lambda char=char: text.set(text.get() + ' ' + char + ' '))

        frm = frame(self, BOTTOM)
        button(frm, LEFT, 'eval', lambda: self.eval(text))
        button(frm, LEFT, 'clear', lambda: text.set(''))
Exemplo n.º 9
0
    def makeWidgets(self, fg, bg, font):  # 7 frames plus text-entry
        self.entry = entry(self, TOP, self.text)  # font, color configurable
        self.entry.config(font=font)  # 3.0: make display larger
        self.entry.config(justify=RIGHT)  # 3.0: on right, not left
        for row in self.Operands:
            frm = frame(self, TOP)
            for char in row:
                button(frm,
                       LEFT,
                       char,
                       lambda op=char: self.onOperand(op),
                       fg=fg,
                       bg=bg,
                       font=font)

        frm = frame(self, TOP)
        for char in self.Operators:
            button(frm,
                   LEFT,
                   char,
                   lambda op=char: self.onOperator(op),
                   fg=bg,
                   bg=fg,
                   font=font)

        frm = frame(self, TOP)
        button(frm, LEFT, 'dot ', lambda: self.onOperand('.'))
        button(frm, LEFT, ' E+ ',
               lambda: self.text.set(self.text.get() + 'E+'))
        button(frm, LEFT, ' E- ',
               lambda: self.text.set(self.text.get() + 'E-'))
        button(frm, LEFT, 'cmd ', self.onMakeCmdline)
        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, 'hist ', self.onHist)
        button(frm, LEFT, 'clear', self.onClear)
Exemplo n.º 10
0
    def makeWidgets(self, fg, bg, font):             # 7 frames plus text-entry
        self.entry = entry(self, TOP, self.text)     # font, color configurable
        self.entry.config(font=font)                 # 3.0: make display larger
        self.entry.config(justify=RIGHT)             # 3.0: on right, not left
        for row in self.Operands:
            frm = frame(self, TOP)
            for char in row:
                button(frm, LEFT, char,
                            lambda op=char: self.onOperand(op),
                            fg=fg, bg=bg, font=font)

        frm = frame(self, TOP)
        for char in self.Operators:
            button(frm, LEFT, char,
                        lambda op=char: self.onOperator(op),
                        fg=bg, bg=fg, font=font)

        frm = frame(self, TOP)
        button(frm, LEFT, 'dot ', lambda: self.onOperand('.'))
        button(frm, LEFT, ' E+ ', lambda: self.text.set(self.text.get()+'E+'))
        button(frm, LEFT, ' E- ', lambda: self.text.set(self.text.get()+'E-'))
        button(frm, LEFT, 'cmd ', self.onMakeCmdline)
        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, 'hist ', self.onHist)
        button(frm, LEFT, 'clear', self.onClear)
Exemplo n.º 11
0
class CalcGuiPlus(Toplevel):
    def __init__(self, **args):
        Toplevel.__init__(self)
        label(self, TOP, 'PyCalc Plus - Container')
        self.calc = 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 expr=expr: self.onExtra(expr)))
        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)
    CalcGuiPlus(**getCalcArgs()).mainloop()       # -bg,-fg to calcgui
Exemplo n.º 12
0

class CalcGuiPlus(Toplevel):
    def __init__(self, **args):
        Toplevel.__init__(self)
        label(self, TOP, 'PyCalc Plus - Container')
        self.calc = 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 expr=expr: self.onExtra(expr)))
        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)
    CalcGuiPlus(**getCalcArgs()).mainloop()  # -bg,-fg to calcgui
Exemplo n.º 13
0
 def makeMainBox(self):
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, 'next', self.onNext)  # next in list
     button(frm, LEFT, 'prev', self.onPrev)  # backup in list
     button(frm, LEFT, 'find', self.onFind)  # find from key
     frm = frame(self, TOP)
     self.keytext = StringVar()  # current record's key
     label(frm, LEFT, 'KEY=>')  # change before 'find'
     entry(frm, LEFT, self.keytext)
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, 'store', self.onStore)  # updated entry data
     button(frm, LEFT, 'new', self.onNew)  # clear fields
     button(frm, LEFT, 'index', self.onMakeList)  # show key list
     button(frm, LEFT, 'delete', self.onDelete)  # show key list
     button(self, BOTTOM, 'quit', self.quit)  # from guimixin
Exemplo n.º 14
0
 def makeMainBox(self):
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, "next", self.onNext)  # next in list
     button(frm, LEFT, "prev", self.onPrev)  # backup in list
     button(frm, LEFT, "find", self.onFind)  # find from key
     frm = frame(self, TOP)
     self.keytext = StringVar()  # current record's key
     label(frm, LEFT, "KEY=>")  # change before 'find'
     entry(frm, LEFT, self.keytext)
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, "store", self.onStore)  # updated entry data
     button(frm, LEFT, "new", self.onNew)  # clear fields
     button(frm, LEFT, "index", self.onMakeList)  # show key list
     button(frm, LEFT, "delete", self.onDelete)  # show key list
     button(self, BOTTOM, "quit", self.quit)  # from guimixin
Exemplo n.º 15
0
 def makeMainBox(self):
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, 'next',  self.onNext)       # next in list
     button(frm, LEFT, 'prev',  self.onPrev)       # backup in list
     button(frm, LEFT, 'find',  self.onFind)       # find from key
     frm = frame(self, TOP)
     self.keytext = StringVar()                    # current record's key
     label(frm, LEFT, 'KEY=>')                     # change before 'find'
     entry(frm, LEFT,  self.keytext)             
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm,  LEFT,  'store',  self.onStore)     # updated entry data
     button(frm,  LEFT,  'new',    self.onNew)       # clear fields
     button(frm,  LEFT,  'index',  self.onMakeList)  # show key list
     button(frm,  LEFT,  'delete', self.onDelete)    # show key list
     button(self, BOTTOM,'quit',   self.quit)        # from guimixin