2017-06-11 289 views
0

我有下面的代码来做一些ocr的东西。当这完成后,我想生成一些窗口。但是,每当我运行我的代码,我得到了第13行的以下错误:unindent does not match any outer indentation level我认为这很奇怪,因为我没有看到我的代码中有任何奇怪的缩进。见下面我的代码:tkinter上的python缩进错误

import Tkinter as tk 
from os import * 
from PIL import Image 
from tesserocr import PyTessBaseAPI, RIL 

root = tk.Tk() 
tk.Label(root, text="this is the root window").pack() 
root.geometry("200x20") 

def window(x, y, w, h): 

    display = tk.Toplevel() 

线下生成错误:

display.geometry('%dx%d+%d+%d' % (w, h, x, y)) 
    tk.Label(display, text="sensitive info").pack() 


def main(): 
    path = "~/Desktop/media_argeology/Check_sensitive/" 
    system("mkdir -p {0}".format(path))  
    system("screencapture {0}temp.png".format(path)) 
    system('sips -Z 4000 temp.png') 


    image = Image.open('temp.png') 
    with PyTessBaseAPI() as api: 
     api.SetImage(image) 
     boxes = api.GetComponentImages(RIL.TEXTLINE, True) 
     for i, (im, box, _, _) in enumerate(boxes): 
      window(box['x'], box['y'], box['w'], box['h']) 


    print "exit first function" 



main() 
root.mainloop() 

我是很新的蟒蛇,但我有其他语言的一些编程经验。任何帮助是极大的赞赏!

+1

你可能有标签和空格的代码中的组合。这是我最好的猜测 – SarathSprakash

+0

没问题给它一张支票 – FutureCake

+1

你甚至可以在问题的源头看到它。 'display = ...'这一行用一个制表符缩进,下面一行用四个空格。 –

回答

1

空间,是压痕的首选方法

你确定你是不是混合在你的缩进空白制表符和空格? (这将导致该错误。)

注意,建议您不要在Python程序中使用的标签

退房Tabs or spaces?

0

此错误显示您在代码中混合列表和四个空格缩进。在编辑器中检查您的代码,该代码可以突出显示选项卡并将其替换为四个空格。