2017-06-11 284 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

此錯誤顯示您在代碼中混合列表和四個空格縮進。在編輯器中檢查您的代碼,該代碼可以突出顯示選項卡並將其替換爲四個空格。