-1

I am making a calculator (using tkinter) and I need to have a limit so if the user enters an input of more than 999, an error message appears and the numbers are not calculated (it is a school project). When I run the script from below, at school it just appears with a blank GUI and on my home computer it says 'unindent does not match any outer indentation level'. How can I solve this? Thanks P.S. I am using Python 3.3.2

   def calc(self):
       try:
           self.display.set(self.validate_result(eval(self.display.get())))
           self.need_clr = True
           except:
               showerror('Operation Error', 'Illegal Operation')
               self.display.set('')
               self.need_clr = False
               def validate_result(self, result):
                   if result >= 1000:
                       raise ValueError('result too big!')
                    else:
                        return result

1 Answers1

1

Python uses indentation to distinguish levels of scope.

Here all your code seems to be entirely indented, so Python thinks all your code is in an inner scope, and tries to find the outer scope that contains it, but there isn't any.

You should try with this indentation :

def calc(self):
    try:
        ...

def calc(self):
    try:
        ...

Edit : also, you seem to have other indentation problems in the second function. You must align except with try, and there is one space missing before if result >= 1000:.

kjaquier
  • 824
  • 4
  • 11
  • This has fixed the indentation error, but when I run the script, a blank GUI appears with no buttons. Any suggestions? (the code usually works without this code) – user3742334 Jun 24 '14 at 21:20
  • It may be another problem then. Look at the output to see if there's an exception or something. If not, it's probably a problem with your GUI. I would suggest to compare your code with some tkinter tutorial (you can take a look at [these](https://wiki.python.org/moin/TkInter)). – kjaquier Jun 24 '14 at 22:10