Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: python calc

  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts

    python calc

    I have this simple calc I got from a book but it doesn't work can someone help

    Code:
    from java import awt
    from pawt import swing
                                                                                             
    labels = ['0','1','2','+',
              '3','4','5','-',
              '6','7','8','*',
              '9','.','=','/']
                                                                                             
    keys = swing.JPanel(awt.GridLayout(4, 4))
    display = swing.JTextField()
                                                                                             
    def push(event):
            display.text = str(eval(display.text))
            display.selectAll()
                                                                                             
    for label in labels:
            key = swing.JButton(label)
            if label == '=':
                   key.actionPerformed = enter
            else:
                    key.actionPerformed = push
            keys.add(key)
                                                                                             
    panel = swing.JPanel(awt.BorderLayout())
    panel.add("North", display)
    panel.add("Center", keys)
    swing.test(panel)
    but my error is from the line

    Code:
                    key.actionPerformed = enter
    and I don't understand why...the error says

    Traceback (innermost last):
    File "calc.py", line 19, in ?
    NameError: enter

    any help?


    Jason

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    never mind, I forgot to add the enter function among some other errors...thanks


    Jason


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •